diff --git a/errors.js b/errors.js index 37f42f4ff..da1287dd3 100644 --- a/errors.js +++ b/errors.js @@ -371,6 +371,14 @@ class ErrParentDoesNotVisible extends TalkError { } } +class ErrPasswordIncorrect extends TalkError { + constructor() { + super('Your current password was entered incorrectly', { + translation_key: 'PASSWORD_INCORRECT', + }); + } +} + module.exports = { TalkError, ErrAlreadyExists, @@ -395,6 +403,7 @@ module.exports = { ErrNotFound, ErrNotVerified, ErrParentDoesNotVisible, + ErrPasswordIncorrect, ErrPasswordResetToken, ErrPasswordTooShort, ErrPermissionUpdateUsername, diff --git a/graph/mutators/user.js b/graph/mutators/user.js index 8657905d9..1f43ca838 100644 --- a/graph/mutators/user.js +++ b/graph/mutators/user.js @@ -1,4 +1,8 @@ -const { ErrNotFound, ErrNotAuthorized } = require('../../errors'); +const { + ErrNotFound, + ErrNotAuthorized, + ErrPasswordIncorrect, +} = require('../../errors'); const Users = require('../../services/users'); const migrationHelpers = require('../../services/migration/helpers'); const { @@ -170,7 +174,7 @@ const changeUserPassword = async (ctx, oldPassword, newPassword) => { // Verify the old password. const validPassword = await user.verifyPassword(oldPassword); if (!validPassword) { - throw new ErrNotAuthorized(); + throw new ErrPasswordIncorrect(); } // Change the users password now. diff --git a/locales/en.yml b/locales/en.yml index 3d2fe88c7..e293fb40b 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -225,6 +225,7 @@ en: embedlink: copy: "Copy to Clipboard" error: + PASSWORD_INCORRECT: "Your current password was entered incorrectly" COMMENT_PARENT_NOT_VISIBLE: "The comment that you're replying to has been removed or doesn't exist." EMAIL_VERIFICATION_TOKEN_INVALID: "Email verification token is invalid." EMAIL_ALREADY_VERIFIED: "Email address already verified." diff --git a/plugins/talk-plugin-local-auth/client/components/ChangePassword.js b/plugins/talk-plugin-local-auth/client/components/ChangePassword.js index 1ceb1b9f5..010df0826 100644 --- a/plugins/talk-plugin-local-auth/client/components/ChangePassword.js +++ b/plugins/talk-plugin-local-auth/client/components/ChangePassword.js @@ -127,12 +127,11 @@ class ChangePassword extends React.Component { 'success', t('talk-plugin-local-auth.change_password.changed_password_msg') ); + this.clearForm(); + this.disableEditing(); } catch (err) { this.props.notify('error', getErrorMessages(err)); } - - this.clearForm(); - this.disableEditing(); }; onForgotPassword = async () => {