mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-03-06 15:59:16 +05:30
#85: allow activation pages for all visitors
This commit is contained in:
parent
7c4d735c80
commit
80afd16c1e
@ -1,9 +1,13 @@
|
||||
// @flow
|
||||
/* eslint no-unused-vars: off */
|
||||
import type { AuthContext } from 'services/authFlow';
|
||||
|
||||
export default class AbstractState {
|
||||
resolve() {}
|
||||
goBack() {
|
||||
resolve(context: AuthContext, payload: Object) {}
|
||||
goBack(context: AuthContext) {
|
||||
throw new Error('There is no way back');
|
||||
}
|
||||
reject() {}
|
||||
enter() {}
|
||||
leave() {}
|
||||
reject(context: AuthContext, payload: Object) {}
|
||||
enter(context: AuthContext) {}
|
||||
leave(context: AuthContext) {}
|
||||
}
|
||||
|
@ -1,24 +1,20 @@
|
||||
// @flow
|
||||
import logger from 'services/logger';
|
||||
|
||||
import AbstractState from './AbstractState';
|
||||
import CompleteState from './CompleteState';
|
||||
import ResendActivationState from './ResendActivationState';
|
||||
import type { AuthContext } from 'services/authFlow';
|
||||
|
||||
export default class ActivationState extends AbstractState {
|
||||
enter(context) {
|
||||
const {user} = context.getState();
|
||||
|
||||
if (user.isActive) {
|
||||
context.setState(new CompleteState());
|
||||
} else {
|
||||
const url = context.getRequest().path.includes('/activation')
|
||||
? context.getRequest().path
|
||||
: '/activation';
|
||||
context.navigate(url);
|
||||
}
|
||||
enter(context: AuthContext) {
|
||||
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)
|
||||
.then(() => context.setState(new CompleteState()))
|
||||
.catch((err = {}) =>
|
||||
@ -26,7 +22,7 @@ export default class ActivationState extends AbstractState {
|
||||
);
|
||||
}
|
||||
|
||||
reject(context) {
|
||||
reject(context: AuthContext) {
|
||||
context.setState(new ResendActivationState());
|
||||
}
|
||||
}
|
||||
|
@ -53,18 +53,6 @@ describe('ActivationState', () => {
|
||||
|
||||
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', () => {
|
||||
|
@ -11,6 +11,17 @@ import RecoverPasswordState from './RecoverPasswordState';
|
||||
import ActivationState from './ActivationState';
|
||||
import CompleteState from './CompleteState';
|
||||
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 {
|
||||
constructor(actions) {
|
||||
|
@ -1,22 +1,17 @@
|
||||
// @flow
|
||||
import logger from 'services/logger';
|
||||
|
||||
import AbstractState from './AbstractState';
|
||||
import CompleteState from './CompleteState';
|
||||
import ActivationState from './ActivationState';
|
||||
import RegisterState from './RegisterState';
|
||||
import type { AuthContext } from 'services/authFlow';
|
||||
|
||||
export default class ResendActivationState extends AbstractState {
|
||||
enter(context) {
|
||||
const {user} = context.getState();
|
||||
|
||||
if (user.isActive) {
|
||||
context.setState(new CompleteState());
|
||||
} else {
|
||||
context.navigate('/resend-activation');
|
||||
}
|
||||
enter(context: AuthContext) {
|
||||
context.navigate('/resend-activation');
|
||||
}
|
||||
|
||||
resolve(context, payload) {
|
||||
resolve(context: AuthContext, payload: Object) {
|
||||
context.run('resendActivation', payload)
|
||||
.then(() => context.setState(new ActivationState()))
|
||||
.catch((err = {}) =>
|
||||
@ -24,11 +19,11 @@ export default class ResendActivationState extends AbstractState {
|
||||
);
|
||||
}
|
||||
|
||||
reject(context) {
|
||||
reject(context: AuthContext) {
|
||||
context.setState(new ActivationState());
|
||||
}
|
||||
|
||||
goBack(context) {
|
||||
goBack(context: AuthContext) {
|
||||
if (context.prevState instanceof RegisterState) {
|
||||
context.setState(new RegisterState());
|
||||
} else {
|
||||
|
@ -49,18 +49,6 @@ describe('ResendActivationState', () => {
|
||||
|
||||
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', () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import AuthFlow from './AuthFlow';
|
||||
export type {AuthContext} from './AuthFlow';
|
||||
|
||||
import * as actions from 'components/auth/actions';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user