mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-07 00:29:19 +05:30
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
|
import AbstractState from './AbstractState';
|
||
|
import LoginState from './LoginState';
|
||
|
import PermissionsState from './PermissionsState';
|
||
|
import ActivationState from './ActivationState';
|
||
|
import ChangePasswordState from './ChangePasswordState';
|
||
|
|
||
|
export default class CompleteState extends AbstractState {
|
||
|
enter(context) {
|
||
|
const {auth, user} = context.getState();
|
||
|
|
||
|
if (user.isGuest) {
|
||
|
context.setState(new LoginState());
|
||
|
} else if (!user.isActive) {
|
||
|
context.setState(new ActivationState());
|
||
|
} else if (user.shouldChangePassword) {
|
||
|
context.setState(new ChangePasswordState());
|
||
|
} else if (auth.oauth) {
|
||
|
context.run('oAuthComplete').then((resp) => {
|
||
|
location.href = resp.redirectUri;
|
||
|
}, (resp) => {
|
||
|
// TODO
|
||
|
if (resp.unauthorized) {
|
||
|
context.setState(new LoginState());
|
||
|
} else if (resp.acceptRequired) {
|
||
|
context.setState(new PermissionsState());
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
context.navigate('/');
|
||
|
}
|
||
|
}
|
||
|
}
|