#85: allow activation pages for all visitors

This commit is contained in:
SleepWalker 2017-06-07 23:22:51 +03:00
parent 7c4d735c80
commit 80afd16c1e
7 changed files with 37 additions and 54 deletions

View File

@ -1,9 +1,13 @@
// @flow
/* eslint no-unused-vars: off */
import type { AuthContext } from 'services/authFlow';
export default class AbstractState { export default class AbstractState {
resolve() {} resolve(context: AuthContext, payload: Object) {}
goBack() { goBack(context: AuthContext) {
throw new Error('There is no way back'); throw new Error('There is no way back');
} }
reject() {} reject(context: AuthContext, payload: Object) {}
enter() {} enter(context: AuthContext) {}
leave() {} leave(context: AuthContext) {}
} }

View File

@ -1,24 +1,20 @@
// @flow
import logger from 'services/logger'; import logger from 'services/logger';
import AbstractState from './AbstractState'; import AbstractState from './AbstractState';
import CompleteState from './CompleteState'; import CompleteState from './CompleteState';
import ResendActivationState from './ResendActivationState'; import ResendActivationState from './ResendActivationState';
import type { AuthContext } from 'services/authFlow';
export default class ActivationState extends AbstractState { export default class ActivationState extends AbstractState {
enter(context) { enter(context: AuthContext) {
const {user} = context.getState(); const url = context.getRequest().path.includes('/activation')
? context.getRequest().path
if (user.isActive) { : '/activation';
context.setState(new CompleteState()); context.navigate(url);
} else {
const url = context.getRequest().path.includes('/activation')
? context.getRequest().path
: '/activation';
context.navigate(url);
}
} }
resolve(context, payload) { resolve(context: AuthContext, payload: Object) {
context.run('activate', payload) context.run('activate', payload)
.then(() => context.setState(new CompleteState())) .then(() => context.setState(new CompleteState()))
.catch((err = {}) => .catch((err = {}) =>
@ -26,7 +22,7 @@ export default class ActivationState extends AbstractState {
); );
} }
reject(context) { reject(context: AuthContext) {
context.setState(new ResendActivationState()); context.setState(new ResendActivationState());
} }
} }

View File

@ -53,18 +53,6 @@ describe('ActivationState', () => {
state.enter(context); state.enter(context);
}); });
it('should transition to complete state if account activated', () => {
context.getState.returns({
user: {
isActive: true
}
});
expectState(mock, CompleteState);
state.enter(context);
});
}); });
describe('#resolve', () => { describe('#resolve', () => {

View File

@ -11,6 +11,17 @@ import RecoverPasswordState from './RecoverPasswordState';
import ActivationState from './ActivationState'; import ActivationState from './ActivationState';
import CompleteState from './CompleteState'; import CompleteState from './CompleteState';
import ResendActivationState from './ResendActivationState'; import ResendActivationState from './ResendActivationState';
import type AbstractState from './AbstractState';
export type AuthContext = {
run: (actionId: string, payload: Object) => any,
setState: (newState: AbstractState) => void,
getRequest: () => {
path: string,
query: URLSearchParams,
params: Object
}
};
export default class AuthFlow { export default class AuthFlow {
constructor(actions) { constructor(actions) {

View File

@ -1,22 +1,17 @@
// @flow
import logger from 'services/logger'; import logger from 'services/logger';
import AbstractState from './AbstractState'; import AbstractState from './AbstractState';
import CompleteState from './CompleteState';
import ActivationState from './ActivationState'; import ActivationState from './ActivationState';
import RegisterState from './RegisterState'; import RegisterState from './RegisterState';
import type { AuthContext } from 'services/authFlow';
export default class ResendActivationState extends AbstractState { export default class ResendActivationState extends AbstractState {
enter(context) { enter(context: AuthContext) {
const {user} = context.getState(); context.navigate('/resend-activation');
if (user.isActive) {
context.setState(new CompleteState());
} else {
context.navigate('/resend-activation');
}
} }
resolve(context, payload) { resolve(context: AuthContext, payload: Object) {
context.run('resendActivation', payload) context.run('resendActivation', payload)
.then(() => context.setState(new ActivationState())) .then(() => context.setState(new ActivationState()))
.catch((err = {}) => .catch((err = {}) =>
@ -24,11 +19,11 @@ export default class ResendActivationState extends AbstractState {
); );
} }
reject(context) { reject(context: AuthContext) {
context.setState(new ActivationState()); context.setState(new ActivationState());
} }
goBack(context) { goBack(context: AuthContext) {
if (context.prevState instanceof RegisterState) { if (context.prevState instanceof RegisterState) {
context.setState(new RegisterState()); context.setState(new RegisterState());
} else { } else {

View File

@ -49,18 +49,6 @@ describe('ResendActivationState', () => {
state.enter(context); state.enter(context);
}); });
it('should transition to complete state if account activated', () => {
context.getState.returns({
user: {
isActive: true
}
});
expectState(mock, CompleteState);
state.enter(context);
});
}); });
describe('#resolve', () => { describe('#resolve', () => {

View File

@ -1,4 +1,5 @@
import AuthFlow from './AuthFlow'; import AuthFlow from './AuthFlow';
export type {AuthContext} from './AuthFlow';
import * as actions from 'components/auth/actions'; import * as actions from 'components/auth/actions';