2020-07-21 18:00:18 +05:30
|
|
|
import React, { MouseEventHandler } from 'react';
|
2019-12-08 00:32:00 +05:30
|
|
|
import logger from 'app/services/logger';
|
|
|
|
import { disable as disableMFA } from 'app/services/api/mfa';
|
|
|
|
import { FormModel } from 'app/components/ui/form';
|
2017-09-09 19:52:19 +05:30
|
|
|
|
2019-12-12 12:56:23 +05:30
|
|
|
import Context from '../Context';
|
2020-06-04 22:11:27 +05:30
|
|
|
import MfaDisableForm from './MfaDisableForm';
|
|
|
|
import MfaStatus from './MfaStatus';
|
2017-09-09 19:52:19 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default class MfaDisable extends React.Component<
|
2020-05-24 04:38:24 +05:30
|
|
|
{
|
|
|
|
onSubmit: (form: FormModel, sendData: () => Promise<void>) => Promise<void>;
|
|
|
|
onComplete: () => void;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
showForm: boolean;
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
> {
|
2020-05-24 04:38:24 +05:30
|
|
|
static contextType = Context;
|
2020-10-11 22:03:55 +05:30
|
|
|
declare context: React.ContextType<typeof Context>;
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
|
|
state = {
|
|
|
|
showForm: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { showForm } = this.state;
|
|
|
|
|
|
|
|
return showForm ? <MfaDisableForm onSubmit={this.onSubmit} /> : <MfaStatus onProceed={this.onProceed} />;
|
|
|
|
}
|
|
|
|
|
2020-07-21 18:00:18 +05:30
|
|
|
onProceed: MouseEventHandler<HTMLAnchorElement> = (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
this.setState({ showForm: true });
|
|
|
|
};
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
|
|
onSubmit = (form: FormModel) => {
|
|
|
|
return this.props
|
|
|
|
.onSubmit(form, () => {
|
|
|
|
const { totp, password } = form.serialize() as {
|
|
|
|
totp: string;
|
|
|
|
password?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
return disableMFA(this.context.userId, totp, password);
|
|
|
|
})
|
|
|
|
.then(() => this.props.onComplete())
|
|
|
|
.catch((resp) => {
|
|
|
|
const { errors } = resp || {};
|
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
return Promise.reject(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error('MFA: Unexpected disable form result', {
|
|
|
|
resp,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-09-09 19:52:19 +05:30
|
|
|
}
|