Skip to content

Commit

Permalink
Merge pull request #1818 from jfromaniello/do_not_autologin_when_capt…
Browse files Browse the repository at this point in the history
…cha_is_required

[CAUTH-373] do not autologin the user if captcha is required
  • Loading branch information
lbalmaceda committed Mar 6, 2020
2 parents 625744e + 5a23b94 commit 034192a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/connection/database/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ function signUpSuccess(id, result, popupHandler) {
l.emitEvent(lock, 'signup success', result);

if (shouldAutoLogin(lock)) {
const isCaptchaRequired = l.captcha(lock) && l.captcha(lock).get('required');

if (isCaptchaRequired) {
return successCaptchaRequired(id);
}

swap(updateEntity, 'lock', id, m => m.set('signedUp', true));

// TODO: check options, redirect is missing
Expand Down Expand Up @@ -175,6 +181,20 @@ function autoLogInError(id, error) {
});
}

function successCaptchaRequired(id) {
swap(updateEntity, 'lock', id, m => {
if (!hasScreen(m, 'login')) {
return l.setSubmitting(m, false);
}
// _ prevents cleaning the fields
m = l.setSubmitting(setScreen(m, 'login', ['_']), false);

const message = i18n.str(m, ['error', 'signUp', 'captcha_required']);

return l.setGlobalSuccess(m, message);
});
}

export function resetPassword(id) {
validateAndSubmit(id, ['email'], m => {
const params = {
Expand Down
6 changes: 0 additions & 6 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,6 @@ export function loginErrorMessage(m, error, type) {
code = 'password_change_required';
}

if (code === 'invalid_captcha') {
return captcha(m).get('type') === 'code'
? i18n.html(m, 'captchaCodeInputPlaceholder')
: i18n.html(m, 'captchaMathInputPlaceholder');
}

return (
i18n.html(m, ['error', 'login', code]) || i18n.html(m, ['error', 'login', 'lock.fallback'])
);
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
login: {
blocked_user: 'The user is blocked.',
invalid_user_password: 'Wrong credentials.',
invalid_captcha: 'The text you entered was incorrect. <br /> Please try again.',
'lock.fallback': "We're sorry, something went wrong when attempting to log in.",
'lock.invalid_code': 'Wrong code.',
'lock.invalid_email_password': 'Wrong email or password.',
Expand Down Expand Up @@ -38,6 +39,7 @@ export default {
},
signUp: {
invalid_password: 'Password is invalid.',
captcha_required: 'Enter the code shown below to finish signing up.',
'lock.fallback': "We're sorry, something went wrong when attempting to sign up.",
password_dictionary_error: 'Password is too common.',
password_no_user_info_error: 'Password is based on user information.',
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
login: {
blocked_user: 'El usuario se encuentra bloqueado.',
invalid_user_password: 'Credenciales inválidas.',
invalid_captcha: 'El texto ingresado es incorrecto. <br /> Por favor, vuelva a intentarlo.',
'lock.fallback': 'Ocurrió un error al iniciar sesión.',
'lock.invalid_code': 'Código inválido.',
'lock.invalid_email_password': 'Correo y contraseña inválidos.',
Expand Down Expand Up @@ -39,6 +40,8 @@ export default {
},
signUp: {
invalid_password: 'La contraseña es inválida.',
captcha_required:
'Ingrese el código que se muestra a continuación para finalizar el registro.',
'lock.fallback': 'Ocurrió un error durante el registro.',
password_dictionary_error: 'La constraseña es muy común.',
password_no_user_info_error: 'La constraseña es similar a los datos del usuario.',
Expand Down

0 comments on commit 034192a

Please sign in to comment.