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/server/methods/setUsername.coffee

26 lines
642 B

slug = (text) ->
text = slugify text, '.'
return text.replace(/[^0-9a-z-_.]/g, '')
usernameIsAvaliable = (username) ->
if username.length < 1
return false
return not Meteor.users.findOne({username: username})?
Meteor.methods
setUsername: (username) ->
if not Meteor.userId()
throw new Meteor.Error 203, '[methods] typingStatus -> Usuário não logado'
user = Meteor.user()
if user.username?
throw new Meteor.Error 'username-already-setted'
if not usernameIsAvaliable username
throw new Meteor.Error 'username-unavaliable'
Meteor.users.update({_id: user._id}, {$set: {username: username}})
return username