Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added password confirmation support on signup and password reset pages. #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/entry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AccountsEntry =
entrySignUp: '/sign-up'
extraSignUpFields: []
showOtherLoginServices: true
requirePasswordConfirmation: false

isStringEmail: (email) ->
emailPattern = /^([\w.-]+)@([\w.-]+)\.([a-zA-Z.]{2,6})$/i
Expand Down
3 changes: 3 additions & 0 deletions client/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
2 changes: 2 additions & 0 deletions client/t9n/english.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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."
Expand Down
9 changes: 8 additions & 1 deletion client/views/resetPassword/resetPassword.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions client/views/resetPassword/resetPassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
<h3>{{t9n "resetYourPassword"}}</h3>
<form id='resetPassword'>
<div class="form-group">
{{#if showPasswordConfirmation}}
<label>{{t9n "password"}}</label>
{{/if}}
<input type="password" name="new-password" class="form-control" value=''>
</div>
{{#if showPasswordConfirmation}}
<div class="form-group">
<label>{{t9n "confirmPassword"}}</label>
<input type="password" name="new-password2" class="form-control" value=''>
</div>
{{/if}}
<button type="submit" class="btn btn-default">{{t9n "updateYourPassword"}}</button>
</form>
{{#if showSignupCode}}
Expand Down
9 changes: 8 additions & 1 deletion client/views/signUp/signUp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ 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


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
Expand Down
9 changes: 8 additions & 1 deletion client/views/signUp/signUp.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ <h3>{{t9n "createAccount"}}</h3>

<div class="form-group">
<label>{{t9n "password"}}</label>
<input type="password" class="form-control" value=''>
<input type="password" class="form-control" name="password1" value=''>
</div>

{{#if showPasswordConfirmation}}
<div class="form-group">
<label>{{t9n "confirmPassword"}}</label>
<input type="password" class="form-control" name="password2" value=''>
</div>
{{/if}}

{{#if showSignupCode}}
<div class="form-group">
<label>{{t9n "signupCode"}}</label>
Expand Down