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

47 lines
1.4 KiB

Meteor.methods
saveUserProfile: (settings) ->
9 years ago
check settings, Object
unless RocketChat.settings.get("Accounts_AllowUserProfileChange")
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'saveUserProfile' })
unless Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'saveUserProfile' }
user = RocketChat.models.Users.findOneById Meteor.userId()
checkPassword = (user, currentPassword) ->
unless s.trim(user?.services?.password?.bcrypt)
return true
unless currentPassword
return false
passCheck = Accounts._checkPassword(user, { digest: currentPassword, algorithm: 'sha-256' });
if passCheck.error
return false
return true
if settings.newPassword?
unless checkPassword user, settings.currentPassword
throw new Meteor.Error('error-invalid-password', 'Invalid password', { method: 'saveUserProfile' })
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?
unless checkPassword user, settings.currentPassword
throw new Meteor.Error('error-invalid-password', 'Invalid password', { method: 'saveUserProfile' })
Meteor.call 'setEmail', settings.email
profile = {}
RocketChat.models.Users.setProfile Meteor.userId(), profile
return true