2019-12-08 00:32:00 +05:30
|
|
|
import logger from 'app/services/logger';
|
2017-08-23 00:09:08 +05:30
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import { getCredentials } from 'app/components/auth/reducer';
|
2017-08-23 00:09:08 +05:30
|
|
|
|
|
|
|
import AbstractState from './AbstractState';
|
|
|
|
import CompleteState from './CompleteState';
|
|
|
|
import PasswordState from './PasswordState';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { AuthContext } from './AuthFlow';
|
2017-08-23 00:09:08 +05:30
|
|
|
|
|
|
|
export default class MfaState extends AbstractState {
|
2020-05-24 04:38:24 +05:30
|
|
|
enter(context: AuthContext): Promise<void> | void {
|
|
|
|
const { login, password, isTotpRequired } = getCredentials(context.getState());
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
if (login && password && isTotpRequired) {
|
|
|
|
context.navigate('/mfa');
|
|
|
|
} else {
|
|
|
|
context.setState(new CompleteState());
|
|
|
|
}
|
2017-08-23 00:09:08 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
resolve(context: AuthContext, { totp }: { totp: string }): Promise<void> | void {
|
|
|
|
const { login, password, rememberMe } = getCredentials(context.getState());
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return context
|
|
|
|
.run('login', {
|
|
|
|
totp,
|
|
|
|
password,
|
|
|
|
rememberMe,
|
|
|
|
login,
|
|
|
|
})
|
|
|
|
.then(() => context.setState(new CompleteState()))
|
|
|
|
.catch((err = {}) => err.errors || logger.warn('Error logging in', err));
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
goBack(context: AuthContext) {
|
|
|
|
context.setState(new PasswordState());
|
|
|
|
}
|
2017-08-23 00:09:08 +05:30
|
|
|
}
|