diff --git a/client/src/containers/Authentication/Login.js b/client/src/containers/Authentication/Login.js index 6dabb1606..3fe43f534 100644 --- a/client/src/containers/Authentication/Login.js +++ b/client/src/containers/Authentication/Login.js @@ -25,24 +25,26 @@ import { compose } from 'utils'; const ERRORS_TYPES = { INVALID_DETAILS: 'INVALID_DETAILS', USER_INACTIVE: 'USER_INACTIVE', + LOGIN_TO_MANY_ATTEMPTS: 'LOGIN_TO_MANY_ATTEMPTS', }; -function Login({ - requestLogin, -}) { +function Login({ requestLogin }) { const { formatMessage } = useIntl(); const history = useHistory(); const [shown, setShown] = useState(false); - const passwordRevealer = () => { setShown(!shown); }; - + const passwordRevealer = () => { + setShown(!shown); + }; // Validation schema. const loginValidationSchema = Yup.object().shape({ crediential: Yup.string() .required() - .email().label(formatMessage({id:'email'})), + .email() + .label(formatMessage({ id: 'email' })), password: Yup.string() .required() - .min(4).label(formatMessage({id:'password'})) + .min(4) + .label(formatMessage({ id: 'password' })), }); // Formik validation schema and submit handler. @@ -62,58 +64,97 @@ function Login({ requestLogin({ crediential: values.crediential, password: values.password, - }).then(() => { - setSubmitting(false); - }).catch((errors) => { - const toastBuilders = []; - if (errors.find((e) => e.type === ERRORS_TYPES.INVALID_DETAILS)) { - toastBuilders.push({ - message: formatMessage({ id: 'email_and_password_entered_did_not_match' }), - intent: Intent.DANGER, + }) + .then(() => { + setSubmitting(false); + }) + .catch((errors) => { + const toastBuilders = []; + if (errors.find((e) => e.type === ERRORS_TYPES.INVALID_DETAILS)) { + toastBuilders.push({ + message: formatMessage({ + id: 'email_and_password_entered_did_not_match', + }), + intent: Intent.DANGER, + }); + } + if (errors.find((e) => e.type === ERRORS_TYPES.USER_INACTIVE)) { + toastBuilders.push({ + message: formatMessage({ + id: 'the_user_has_been_suspended_from_admin', + }), + intent: Intent.DANGER, + }); + } + if ( + errors.find((e) => e.type === ERRORS_TYPES.LOGIN_TO_MANY_ATTEMPTS) + ) { + toastBuilders.push({ + message: formatMessage({ + id: 'your_account_has_been_locked', + }), + intent: Intent.DANGER, + }); + } + toastBuilders.forEach((builder) => { + Toaster.show(builder); }); - } - if (errors.find((e) => e.type === ERRORS_TYPES.USER_INACTIVE)) { - toastBuilders.push({ - message: formatMessage({ id: 'the_user_has_been_suspended_from_admin' }), - intent: Intent.DANGER, - }); - } - toastBuilders.forEach(builder => { - Toaster.show(builder); + setSubmitting(false); }); - setSubmitting(false); - }); }, }); - const passwordRevealerTmp = useMemo(() => ( - passwordRevealer()}> - - <> - - - <> - - ), [shown, passwordRevealer]); + const passwordRevealerTmp = useMemo( + () => ( + passwordRevealer()}> + + <> + {' '} + + + + + + + <> + {' '} + + + + + + + ), + [shown, passwordRevealer], + ); return ( -
+
-

+

+ +

- + + {' '} + +
} - intent={(errors.crediential && touched.crediential) && Intent.DANGER} - helperText={} + intent={errors.crediential && touched.crediential && Intent.DANGER} + helperText={ + + } className={'form-group--crediential'} > @@ -122,22 +163,22 @@ function Login({ } labelInfo={passwordRevealerTmp} - intent={(errors.password && touched.password) && Intent.DANGER} - helperText={} + intent={errors.password && touched.password && Intent.DANGER} + helperText={ + + } className={'form-group--password has-password-revealer'} >
- +
@@ -165,6 +206,4 @@ function Login({ ); } -export default compose( - withAuthenticationActions, -)(Login); \ No newline at end of file +export default compose(withAuthenticationActions)(Login); diff --git a/client/src/lang/en/index.js b/client/src/lang/en/index.js index 165302da5..e3697de25 100644 --- a/client/src/lang/en/index.js +++ b/client/src/lang/en/index.js @@ -876,4 +876,6 @@ export default { day: 'day.', day_partially_paid: 'Day Partially paid', paid: 'Paid', + your_account_has_been_locked: + 'Your account has been locked due to repeated failed login attempts. Please wait a few minutes before trying again.', };