From 8f7abdb6f09bf332213c06a0282e94cf88b18ed4 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 4 Jan 2015 10:43:52 -0500 Subject: [PATCH] Added password confirmation support on signup and password reset pages. --- client/entry.coffee | 1 + client/helpers.coffee | 3 +++ client/t9n/english.coffee | 2 ++ client/views/resetPassword/resetPassword.coffee | 9 ++++++++- client/views/resetPassword/resetPassword.html | 9 +++++++++ client/views/signUp/signUp.coffee | 9 ++++++++- client/views/signUp/signUp.html | 9 ++++++++- 7 files changed, 39 insertions(+), 3 deletions(-) diff --git a/client/entry.coffee b/client/entry.coffee index fc1436f8..bd3dce5d 100644 --- a/client/entry.coffee +++ b/client/entry.coffee @@ -9,6 +9,7 @@ AccountsEntry = entrySignUp: '/sign-up' extraSignUpFields: [] showOtherLoginServices: true + requirePasswordConfirmation: false isStringEmail: (email) -> emailPattern = /^([\w.-]+)@([\w.-]+)\.([a-zA-Z.]{2,6})$/i diff --git a/client/helpers.coffee b/client/helpers.coffee index fb084259..7c57b62d 100644 --- a/client/helpers.coffee +++ b/client/helpers.coffee @@ -33,6 +33,9 @@ UI.registerHelper 'loginServices', -> UI.registerHelper 'showSignupCode', -> AccountsEntry.settings.showSignupCode is true +UI.registerHelper 'showPasswordConfirmation', -> + AccountsEntry.settings.requirePasswordConfirmation is true + UI.registerHelper 'passwordLoginService', -> !!Package['accounts-password'] diff --git a/client/t9n/english.coffee b/client/t9n/english.coffee index 6181f772..cc76550a 100644 --- a/client/t9n/english.coffee +++ b/client/t9n/english.coffee @@ -11,6 +11,7 @@ en = resetYourPassword: "Reset your password" updateYourPassword: "Update your password" password: "Password" + confirmPassword: "Confirm Password" usernameOrEmail: "Username or email" email: "Email" ifYouAlreadyHaveAnAccount: "If you already have an account" @@ -33,6 +34,7 @@ en = minChar: "7 character minimum password." pwOneLetter: "Password requires 1 letter." pwOneDigit: "Password must have at least one digit." + pwNoMatch: "Passwords must match." usernameRequired: "Username is required." emailRequired: "Email is required." signupCodeRequired: "Registration code is required." diff --git a/client/views/resetPassword/resetPassword.coffee b/client/views/resetPassword/resetPassword.coffee index d957dfd2..9c719f2c 100644 --- a/client/views/resetPassword/resetPassword.coffee +++ b/client/views/resetPassword/resetPassword.coffee @@ -8,11 +8,18 @@ Template.entryResetPassword.events 'submit #resetPassword': (event) -> event.preventDefault() - password = $('input[type="password"]').val() + password = $('input[name="new-password"]').val() passwordErrors = do (password)-> errMsg = [] msg = false + + if AccountsEntry.settings.requirePasswordConfirmation + password2 = $('input[name="new-password2"]').val() + + if password isnt password2 + errMsg.push t9n("error.pwNoMatch") + if password.length < 7 errMsg.push t9n("error.minChar") if password.search(/[a-z]/i) < 0 diff --git a/client/views/resetPassword/resetPassword.html b/client/views/resetPassword/resetPassword.html index b9dfeb0a..35d26889 100644 --- a/client/views/resetPassword/resetPassword.html +++ b/client/views/resetPassword/resetPassword.html @@ -13,8 +13,17 @@

{{t9n "resetYourPassword"}}

+ {{#if showPasswordConfirmation}} + + {{/if}}
+ {{#if showPasswordConfirmation}} +
+ + +
+ {{/if}}
{{#if showSignupCode}} diff --git a/client/views/signUp/signUp.coffee b/client/views/signUp/signUp.coffee index 8eb32bc8..a2864983 100644 --- a/client/views/signUp/signUp.coffee +++ b/client/views/signUp/signUp.coffee @@ -78,7 +78,7 @@ AccountsEntry.entrySignUpEvents = { formValues = SimpleForm.processForm(event.target) extraFields = _.pluck(AccountsEntry.settings.extraSignUpFields, 'field') filteredExtraFields = _.pick(formValues, extraFields) - password = t.find('input[type="password"]').value + password = t.find('input[name="password1"]').value fields = AccountsEntry.settings.passwordSignupFields @@ -86,6 +86,13 @@ AccountsEntry.entrySignUpEvents = { passwordErrors = do (password)-> errMsg = [] msg = false + + if AccountsEntry.settings.requirePasswordConfirmation + password2 = t.find('input[name="password2"]').value + + if password2 isnt password + errMsg.push t9n("error.pwNoMatch") + if password.length < 7 errMsg.push t9n("error.minChar") if password.search(/[a-z]/i) < 0 diff --git a/client/views/signUp/signUp.html b/client/views/signUp/signUp.html index b2a693c0..64b50528 100644 --- a/client/views/signUp/signUp.html +++ b/client/views/signUp/signUp.html @@ -49,9 +49,16 @@

{{t9n "createAccount"}}

- +
+ {{#if showPasswordConfirmation}} +
+ + +
+ {{/if}} + {{#if showSignupCode}}