accounts-frontend/src/services/authFlow/PasswordState.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

import logger from 'services/logger';
2016-03-02 02:06:14 +05:30
import AbstractState from './AbstractState';
import CompleteState from './CompleteState';
import ForgotPasswordState from './ForgotPasswordState';
import LoginState from './LoginState';
2016-03-02 02:06:14 +05:30
export default class PasswordState extends AbstractState {
enter(context) {
const {auth} = context.getState();
2016-03-02 02:06:14 +05:30
if (auth.login) {
2016-03-02 02:06:14 +05:30
context.navigate('/password');
} else {
context.setState(new CompleteState());
2016-03-02 02:06:14 +05:30
}
}
resolve(context, {password, rememberMe}) {
const {auth: {login}} = context.getState();
2016-03-02 02:06:14 +05:30
return context.run('login', {
2016-03-02 02:06:14 +05:30
password,
rememberMe,
login
2016-03-02 02:06:14 +05:30
})
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn(err));
2016-03-02 02:06:14 +05:30
}
reject(context) {
context.setState(new ForgotPasswordState());
}
goBack(context) {
context.run('setLogin', null);
2016-03-02 02:06:14 +05:30
context.setState(new LoginState());
}
}