Skip to content

Commit

Permalink
Merge pull request #101 from bshardi/master
Browse files Browse the repository at this point in the history
Take Two on Case Sensitive Username and Email - #65
  • Loading branch information
queso committed Mar 8, 2014
2 parents 3071528 + c2736b9 commit 70a5faa
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions client/entry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ AccountsEntry =
homeRoute: '/home'
dashboardRoute: '/dashboard'
passwordSignupFields: 'EMAIL_ONLY'
emailToLower: true
usernameToLower: false

isStringEmail: (email) ->
emailPattern = /^([\w.-]+)@([\w.-]+)\.([a-zA-Z.]{2,6})$/i
if email.match emailPattern then true else false

config: (appConfig) ->
@settings = _.extend(@settings, appConfig)
Expand Down
1 change: 1 addition & 0 deletions client/i18n/english.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ en =
signupCodeRequired: "Signup code is required."
signupCodeIncorrect: "Signup code is incorrect."
signInRequired: "You must be signed in to do that."
usernameIsEmail: "Username cannot be an email address."

T9n.map "en", en
1 change: 1 addition & 0 deletions client/i18n/german.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ de =
signupCodeRequired: "Registrierungscode benötigt."
signupCodeIncorrect: "Registrierungscode ungültig."
signInRequired: "Sie müssen sich anmelden."
usernameIsEmail: "Benutzername kann nicht eine E-Mail."

T9n.map "de", de
1 change: 1 addition & 0 deletions client/i18n/polish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ pl =
signupCodeRequired: "Wymagany jest kod rejestracji."
signupCodeIncorrect: "Kod rejestracji jest nieprawidłowy."
signInRequired: "Musisz być zalogowany, aby to zrobić."
usernameIsEmail: "Nazwa użytkownika nie może być adres e-mail."

T9n.map "pl", pl
1 change: 1 addition & 0 deletions client/i18n/spanish.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ es =
signupCodeRequired: "Código para suscribir es necesario."
signupCodeIncorrect: "Código para suscribir no coincide."
signInRequired: "Debes iniciar sesión para hacer eso."
usernameIsEmail: "Usuario no puede ser Email."

T9n.map "es", es
8 changes: 7 additions & 1 deletion client/views/signIn/signIn.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ Template.entrySignIn.helpers
Template.entrySignIn.events
'submit #signIn': (event) ->
event.preventDefault()
Session.set('email', $('input[name="email"]').val())

email = $('input[name="email"]').val()
if (AccountsEntry.isStringEmail(email) and AccountsEntry.settings.emailToLower) or
(not AccountsEntry.isStringEmail(email) and AccountsEntry.settings.usernameToLower)
email = email.toLowerCase()

Session.set('email', email)
Session.set('password', $('input[name="password"]').val())

Meteor.loginWithPassword(Session.get('email'), Session.get('password'), (error)->
Expand Down
6 changes: 6 additions & 0 deletions client/views/signUp/signUp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Template.entrySignUp.events
t.find('input[name="username"]').value.toLowerCase()
else
undefined
if username and AccountsEntry.settings.usernameToLower then username = username.toLowerCase()

signupCode =
if t.find('input[name="signupCode"]')
Expand All @@ -64,6 +65,7 @@ Template.entrySignUp.events
trimInput t.find('input[type="email"]').value
else
undefined
if AccountsEntry.settings.emailToLower and email then email = email.toLowerCase()

password = t.find('input[type="password"]').value

Expand Down Expand Up @@ -104,6 +106,10 @@ Template.entrySignUp.events
Session.set('entryError', i18n("error.usernameRequired"))
return

if username && AccountsEntry.isStringEmail(username)
Session.set('entryError', i18n("error.usernameIsEmail"))
return

if emailRequired && email.length is 0
Session.set('entryError', i18n("error.emailRequired"))
return
Expand Down

0 comments on commit 70a5faa

Please sign in to comment.