2016-03-02 02:06:14 +05:30
|
|
|
import AbstractState from './AbstractState';
|
|
|
|
import LoginState from './LoginState';
|
|
|
|
import PermissionsState from './PermissionsState';
|
|
|
|
import ActivationState from './ActivationState';
|
|
|
|
import ChangePasswordState from './ChangePasswordState';
|
2016-03-15 12:06:13 +05:30
|
|
|
import FinishState from './FinishState';
|
2016-03-02 02:06:14 +05:30
|
|
|
|
|
|
|
export default class CompleteState extends AbstractState {
|
2016-03-15 12:06:13 +05:30
|
|
|
constructor(options = {}) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
if ('accept' in options) {
|
|
|
|
this.isPermissionsAccepted = options.accept;
|
|
|
|
this.isUserReviewedPermissions = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 02:06:14 +05:30
|
|
|
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());
|
2016-03-16 10:33:23 +05:30
|
|
|
} else if (auth.oauth && auth.oauth.clientId) {
|
2016-03-15 12:06:13 +05:30
|
|
|
if (auth.oauth.code) {
|
|
|
|
context.setState(new FinishState());
|
|
|
|
} else {
|
|
|
|
let data = {};
|
|
|
|
if (this.isUserReviewedPermissions) {
|
|
|
|
data.accept = this.isPermissionsAccepted;
|
2016-03-02 02:06:14 +05:30
|
|
|
}
|
2016-03-15 12:06:13 +05:30
|
|
|
context.run('oAuthComplete', data).then((resp) => {
|
2016-03-21 01:06:30 +05:30
|
|
|
if (resp.redirectUri.startsWith('static_page')) {
|
|
|
|
context.setState(new FinishState());
|
|
|
|
} else {
|
|
|
|
location.href = resp.redirectUri;
|
2016-03-15 12:06:13 +05:30
|
|
|
}
|
|
|
|
}, (resp) => {
|
|
|
|
// TODO
|
|
|
|
if (resp.unauthorized) {
|
|
|
|
context.setState(new LoginState());
|
|
|
|
} else if (resp.acceptRequired) {
|
|
|
|
context.setState(new PermissionsState());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-03-02 02:06:14 +05:30
|
|
|
} else {
|
|
|
|
context.navigate('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|