Skip to content
Snippets Groups Projects
Unverified Commit 8e00fcf8 authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Sets default avatar after setting username for the first time

parent 3494036c
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,8 @@
"Accounts_RegistrationForm_SecretURL_Description": "You must provide a random string that will be added to your registration URL. Example: https://demo.rocket.chat/register/[secret_hash]",
"Accounts_RequireNameForSignUp": "Require Name For Signup",
"Accounts_RequirePasswordConfirmation": "Require Password Confirmation",
"Accounts_SetDefaultAvatar": "Set Default Avatar",
"Accounts_SetDefaultAvatar_Description": "Tries to determine default avatar based on OAuth Account or Gravatar",
"Accounts_ShowFormLogin": "Show form-based Login",
"Accounts_UseDefaultBlockedDomainsList": "Use Default Blocked Domains List",
"Accounts_UseDNSDomainCheck": "Use DNS Domain Check",
......
......@@ -24,14 +24,27 @@ RocketChat._setUsername = (userId, username) ->
unless RocketChat.checkUsernameAvailability username
return false
# If first time setting username, send Enrollment Email
try
if not previousUsername and user.emails?.length > 0 and RocketChat.settings.get 'Accounts_Enrollment_Email'
Accounts.sendEnrollmentEmail(user._id)
catch error
user.username = username
# If first time setting username, check if should set default avatar
if not previousUsername and RocketChat.settings.get('Accounts_SetDefaultAvatar') is true
avatarSuggestions = getAvatarSuggestionForUser user
for service, avatarData of avatarSuggestions
if service isnt 'gravatar'
RocketChat.setUserAvatar(user, avatarData.blob, avatarData.contentType, service)
gravatar = null
break
else
gravatar = avatarData
if gravatar?
RocketChat.setUserAvatar(user, gravatar.blob, gravatar.contentType, 'gravatar')
# Username is available; if coming from old username, update all references
if previousUsername
RocketChat.models.Messages.updateAllUsernamesByUserId user._id, username
......@@ -58,7 +71,6 @@ RocketChat._setUsername = (userId, username) ->
# Set new username
RocketChat.models.Users.setUsername user._id, username
user.username = username
return user
RocketChat.setUsername = RocketChat.RateLimiter.limitFunction RocketChat._setUsername, 1, 60000,
......
......@@ -41,6 +41,7 @@ RocketChat.settings.addGroup 'Accounts', ->
@add 'Accounts_AvatarSize', 200, { type: 'int', enableQuery: {_id: 'Accounts_AvatarResize', value: true} }
@add 'Accounts_AvatarStoreType', 'GridFS', { type: 'select', values: [ { key: 'GridFS', i18nLabel: 'GridFS' }, { key: 'FileSystem', i18nLabel: 'FileSystem' } ] }
@add 'Accounts_AvatarStorePath', '', { type: 'string', enableQuery: {_id: 'Accounts_AvatarStoreType', value: 'FileSystem'} }
@add 'Accounts_SetDefaultAvatar', true, { type: 'boolean' }
RocketChat.settings.addGroup 'OAuth', ->
......
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