The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/packages/rocketchat-lib/server/methods/setUsername.coffee

22 lines
674 B

Meteor.methods
setUsername: (username) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] setUsername -> Invalid user")
console.log '[methods] setUsername -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments
user = Meteor.user()
if user.username is username
return username
if not /^[0-9a-zA-Z-_.]+$/.test username
throw new Meteor.Error 'username-invalid'
if not RocketChat.checkUsernameAvailability username
throw new Meteor.Error 'username-unavailable'
unless RocketChat.setUsername user, username
throw new Meteor.Error 'could-not-change-username', t('Could_not_change_username')
return username