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/saveUserProfile.coffee

35 lines
1.2 KiB

Meteor.methods
saveUserProfile: (settings) ->
unless Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'saveUserProfile' }
user = RocketChat.models.Users.findOneById Meteor.userId()
if s.trim(user?.services?.password?.bcrypt) and not settings.currentPassword
throw new Meteor.Error('error-invalid-password', 'Invalid password', { method: 'saveUserProfile' })
unless RocketChat.settings.get("Accounts_AllowUserProfileChange")
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'saveUserProfile' })
if s.trim(user?.services?.password?.bcrypt)
passCheck = Accounts._checkPassword(user, { digest: settings.currentPassword, algorithm: 'sha-256' });
if passCheck.error
throw new Meteor.Error('error-invalid-password', 'Invalid password', { method: 'saveUserProfile' });
if settings.newPassword?
Accounts.setPassword Meteor.userId(), settings.newPassword, { logout: false }
if settings.realname?
Meteor.call 'setRealName', settings.realname
if settings.username?
Meteor.call 'setUsername', settings.username
if settings.email?
Meteor.call 'setEmail', settings.email
profile = {}
RocketChat.models.Users.setProfile Meteor.userId(), profile
return true