From d2c1c2cec696dce197e6691d207fe4162569f1d0 Mon Sep 17 00:00:00 2001 From: Victor Piousbox Date: Sat, 19 Mar 2016 17:37:08 +0000 Subject: [PATCH] cleanup and moving text strings to a locale object --- common/locales/en/api-v3.json | 3 +++ .../user/auth/POST-user_reset_password.test.js | 2 +- website/src/controllers/api-v3/user.js | 16 +++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/common/locales/en/api-v3.json b/common/locales/en/api-v3.json index 51dc2b5c41..2069398315 100644 --- a/common/locales/en/api-v3.json +++ b/common/locales/en/api-v3.json @@ -13,6 +13,9 @@ "passwordConfirmationMatch": "Password confirmation doesn't match password.", "invalidLoginCredentials": "Incorrect username / email and / or password.", "passwordReset": "If we have your email on file, your password reset link has been sent to your email.", + "passwordResetEmailSubject": "Password Reset for Habitica", + "passwordResetEmailText": "Password for <%= username %> has been reset to <%= newPassword %> . Important! Both username and password are case-sensitive -- you must enter both exactly as shown here. We recommend copying and pasting both instead of typing them. Log in at <%= baseUrl %>. After you have logged in, head to <%= baseUrl %>/#/options/settings/settings and change your password.", + "passwordResetEmailHtml": "Password for <%= username %> has been reset to <%= newPassword %>.

Important! Both username and password are case-sensitive -- you must enter both exactly as shown here. We recommend copying and pasting both instead of typing them.

Log in at <%= baseUrl %>. After you have logged in, head to <%= baseUrl %>/#/options/settings/settings and change your password.", "invalidCredentials": "User not found with given auth credentials.", "accountSuspended": "Account has been suspended, please contact leslie@habitica.com with your UUID \"<%= userId %>\" for assistance.", "onlyFbSupported": "Only Facebook supported currently.", diff --git a/test/api/v3/integration/user/auth/POST-user_reset_password.test.js b/test/api/v3/integration/user/auth/POST-user_reset_password.test.js index 889882c8bc..e64e1332ea 100644 --- a/test/api/v3/integration/user/auth/POST-user_reset_password.test.js +++ b/test/api/v3/integration/user/auth/POST-user_reset_password.test.js @@ -27,7 +27,7 @@ describe('POST /user/reset-password', async () => { }); */ - it('errors is email is not provided', async () => { + it('errors if email is not provided', async () => { await expect(user.post(endpoint)).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', diff --git a/website/src/controllers/api-v3/user.js b/website/src/controllers/api-v3/user.js index 2ab5825958..330b2739f3 100644 --- a/website/src/controllers/api-v3/user.js +++ b/website/src/controllers/api-v3/user.js @@ -104,7 +104,7 @@ api.resetPassword = { let validationErrors = req.validationErrors(); if (validationErrors) throw validationErrors; - let email = req.body.email && req.body.email.toLowerCase(); + let email = req.body.email.toLowerCase(); let salt = passwordUtils.makeSalt(); let newPassword = passwordUtils.makeSalt(); // use a salt as the new password too (they'll change it later) let hashedPassword = passwordUtils.encrypt(newPassword, salt); @@ -117,13 +117,19 @@ api.resetPassword = { sendEmail({ from: 'Habitica ', to: email, - subject: 'Password Reset for Habitica', - text: `Password for ${user.auth.local.username} has been reset to ${newPassword} . Important! Both username and password are case-sensitive -- you must enter both exactly as shown here. We recommend copying and pasting both instead of typing them. Log in at ${nconf.get('BASE_URL')}. After you have logged in, head to ${nconf.get('BASE_URL')}/#/options/settings/settings and change your password.`, - html: `Password for ${user.auth.local.username} has been reset to ${newPassword}

Important! Both username and password are case-sensitive -- you must enter both exactly as shown here. We recommend copying and pasting both instead of typing them.

Log in at ${nconf.get('BASE_URL')}. After you have logged in, head to ${nconf.get('BASE_URL')}/#/options/settings/settings and change your password.`, + subject: res.t('passwordResetEmailSubject'), + text: res.t('passwordResetEmailText', { username: user.auth.local.username, + newPassword, + baseUrl: nconf.get('BASE_URL'), + }), + html: res.t('passwordResetEmailHtml', { username: user.auth.local.username, + newPassword, + baseUrl: nconf.get('BASE_URL'), + }), }); await user.save(); } - res.respond(300, { message: res.t('passwordReset') }); + res.respond(200, { message: res.t('passwordReset') }); }, };