From c1cfd2ca2a242e5723fed36891cceee71470e46c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 12 Jan 2022 10:52:28 -0600 Subject: [PATCH 1/4] MFA login: be less sensitive about the error response --- .../features/auth_login/components/otp_auth_form.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/soapbox/features/auth_login/components/otp_auth_form.js b/app/soapbox/features/auth_login/components/otp_auth_form.js index 05d638bdc..9bd4afa6f 100644 --- a/app/soapbox/features/auth_login/components/otp_auth_form.js +++ b/app/soapbox/features/auth_login/components/otp_auth_form.js @@ -45,10 +45,7 @@ class OtpAuthForm extends ImmutablePureComponent { this.setState({ shouldRedirect: true }); return dispatch(switchAccount(account.id)); }).catch(error => { - this.setState({ isLoading: false }); - if (error.response.data.error === 'Invalid code') { - this.setState({ code_error: true }); - } + this.setState({ isLoading: false, code_error: true }); }); this.setState({ isLoading: true }); event.preventDefault(); @@ -82,11 +79,11 @@ class OtpAuthForm extends ImmutablePureComponent { - { code_error && + {code_error && (
- } + )}
); @@ -255,7 +266,7 @@ class OtpConfirmForm extends ImmutablePureComponent { state = { password: '', - done: false, + isLoading: false, code: '', qrCodeURI: '', confirm_key: '', @@ -275,26 +286,29 @@ class OtpConfirmForm extends ImmutablePureComponent { this.setState({ [e.target.name]: e.target.value }); } - handleOtpConfirmClick = e => { - const { code, password } = this.state; + handleSubmit = e => { const { dispatch, intl } = this.props; + const { code, password } = this.state; + + this.setState({ isLoading: true }); dispatch(confirmMfa('totp', code, password)).then(() => { dispatch(snackbar.success(intl.formatMessage(messages.mfaConfirmSuccess))); + this.context.router.history.push('../auth/edit'); }).catch(error => { dispatch(snackbar.error(intl.formatMessage(messages.confirmFail))); + this.setState({ isLoading: false }); }); - this.context.router.history.push('../auth/edit'); e.preventDefault(); } render() { const { intl } = this.props; - const { qrCodeURI, confirm_key } = this.state; + const { isLoading, qrCodeURI, confirm_key, password, code } = this.state; return ( - +
@@ -319,19 +333,34 @@ class OtpConfirmForm extends ImmutablePureComponent { name='code' onChange={this.handleInputChange} autoComplete='off' + value={code} + disabled={isLoading} />
-
diff --git a/app/soapbox/reducers/security.js b/app/soapbox/reducers/security.js index 01e5686c7..443e80b49 100644 --- a/app/soapbox/reducers/security.js +++ b/app/soapbox/reducers/security.js @@ -3,9 +3,7 @@ import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; import { MFA_FETCH_SUCCESS, MFA_CONFIRM_SUCCESS, - MFA_DISABLE_REQUEST, MFA_DISABLE_SUCCESS, - MFA_DISABLE_FAIL, } from '../actions/mfa'; import { FETCH_TOKENS_SUCCESS, @@ -49,11 +47,8 @@ export default function security(state = initialState, action) { return importMfa(state, fromJS(action.data)); case MFA_CONFIRM_SUCCESS: return enableMfa(state, action.method); - case MFA_DISABLE_REQUEST: case MFA_DISABLE_SUCCESS: return disableMfa(state, action.method); - case MFA_DISABLE_FAIL: - return enableMfa(state, action.method); default: return state; } From f675e7992a9ca0dc5888370920e0f29fa0e50d56 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 12 Jan 2022 12:03:24 -0600 Subject: [PATCH 3/4] MfaForm: improve styles and usability --- app/soapbox/components/button.js | 2 + app/soapbox/features/security/mfa_form.js | 74 +++++++++++++++-------- app/soapbox/locales/en.json | 8 +-- app/styles/components/mfa_form.scss | 27 +++++++-- app/styles/forms.scss | 14 ----- 5 files changed, 75 insertions(+), 50 deletions(-) diff --git a/app/soapbox/components/button.js b/app/soapbox/components/button.js index 43ca98588..25e116154 100644 --- a/app/soapbox/components/button.js +++ b/app/soapbox/components/button.js @@ -8,6 +8,7 @@ import Icon from './icon'; export default class Button extends React.PureComponent { static propTypes = { + type: PropTypes.string, text: PropTypes.node, onClick: PropTypes.func, to: PropTypes.string, @@ -54,6 +55,7 @@ export default class Button extends React.PureComponent { const btn = (