2016-03-02 02:06:14 +05:30
|
|
|
import AbstractState from './AbstractState';
|
|
|
|
import PasswordState from './PasswordState';
|
|
|
|
|
|
|
|
export default class LoginState extends AbstractState {
|
|
|
|
enter(context) {
|
2016-11-13 02:01:44 +05:30
|
|
|
const {auth, user} = context.getState();
|
2016-03-02 02:06:14 +05:30
|
|
|
|
2016-11-13 02:01:44 +05:30
|
|
|
// TODO: it may not allow user to leave password state till he click back or enters password
|
|
|
|
if (auth.login) {
|
2016-03-02 02:06:14 +05:30
|
|
|
context.setState(new PasswordState());
|
2016-11-13 02:01:44 +05:30
|
|
|
} else if (user.isGuest
|
|
|
|
// for the case, when user is logged in and wants to add a new aacount
|
|
|
|
|| /login|password/.test(context.getRequest().path) // TODO: improve me
|
|
|
|
) {
|
2016-03-02 02:06:14 +05:30
|
|
|
context.navigate('/login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(context, payload) {
|
|
|
|
context.run('login', payload)
|
|
|
|
.then(() => context.setState(new PasswordState()));
|
|
|
|
}
|
|
|
|
}
|