Skip to content
Snippets Groups Projects
Commit 70b0e919 authored by Nberton's avatar Nberton
Browse files

Fixed Issue #1468

parent 01b4ed79
No related merge requests found
RocketChat.setUsername = (user, username) -> RocketChat.setUsername = (user, username) ->
console.log("In setUserName")
username = s.trim username username = s.trim username
if not user or not username if not user or not username
return false return false
...@@ -10,12 +11,15 @@ RocketChat.setUsername = (user, username) -> ...@@ -10,12 +11,15 @@ RocketChat.setUsername = (user, username) ->
if user.username is username if user.username is username
return user return user
# Check username availability
unless RocketChat.checkUsernameAvailability username
return false
previousUsername = user.username previousUsername = user.username
# Check username availability or if the user already owns a different casing of the name
if ( !previousUsername or !(username.toLowerCase() == previousUsername.toLowerCase()))
unless RocketChat.checkUsernameAvailability username
return false
# If first time setting username, send Enrollment Email # If first time setting username, send Enrollment Email
if not previousUsername and RocketChat.settings.get 'Accounts_Enrollment_Email' if not previousUsername and RocketChat.settings.get 'Accounts_Enrollment_Email'
Accounts.sendEnrollmentEmail(user._id) Accounts.sendEnrollmentEmail(user._id)
......
...@@ -16,8 +16,13 @@ Meteor.methods ...@@ -16,8 +16,13 @@ Meteor.methods
if not /^[0-9a-zA-Z-_.]+$/.test username if not /^[0-9a-zA-Z-_.]+$/.test username
throw new Meteor.Error 'username-invalid', "#{username} is not a valid username, use only letters, numbers, dots and dashes" throw new Meteor.Error 'username-invalid', "#{username} is not a valid username, use only letters, numbers, dots and dashes"
if not RocketChat.checkUsernameAvailability username if user.username != undefined
throw new Meteor.Error 'username-unavailable', "#{username} is already in use :(" if not username.toLowerCase() == user.username.toLowerCase()
if not RocketChat.checkUsernameAvailability username
throw new Meteor.Error 'username-unavailable', "#{username} is already in use :("
else
if not RocketChat.checkUsernameAvailability username
throw new Meteor.Error 'username-unavailable', "#{username} is already in use :("
unless RocketChat.setUsername user, username unless RocketChat.setUsername user, username
throw new Meteor.Error 'could-not-change-username', "Could not change username" throw new Meteor.Error 'could-not-change-username', "Could not change username"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment