Skip to content
Snippets Groups Projects
Commit 5d7a814d authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #515 from RocketChat/no-email-registration

Allow registration from services without an e-mail address
parents 5dfe136a 84907e92
No related branches found
No related tags found
No related merge requests found
......@@ -56,10 +56,6 @@ Template.loginServices.events
loadingIcon.addClass 'hidden'
serviceIcon.removeClass 'hidden'
if error?.error is 'github-no-public-email'
alert t("github_no_public_email")
return
if error
console.log JSON.stringify(error), error.message
toastr.error error.message
......
......@@ -3,9 +3,6 @@ Accounts.updateOrCreateUserFromExternalService = (serviceName, serviceData, opti
if serviceName not in ['facebook', 'github', 'google', 'meteor-developer', 'linkedin']
return
if serviceName is 'github' and (not serviceData.email? or serviceData.email.trim() is '')
throw new Meteor.Error 'github-no-public-email'
if serviceName is 'meteor-developer'
if _.isArray serviceData?.emails
serviceData.emails.sort (a, b) ->
......@@ -19,24 +16,22 @@ Accounts.updateOrCreateUserFromExternalService = (serviceName, serviceData, opti
if serviceName is 'linkedin'
serviceData.email = serviceData.emailAddress
if not serviceData.email? or serviceData.email.trim() is ''
throw new Meteor.Error 'no-verified-email'
return
# Remove not verified users that have same email
notVerifiedUser = Meteor.users.remove({emails: {$elemMatch: {address: serviceData.email, verified: false}}})
# Try to get existent user with same email verified
user = Meteor.users.findOne({emails: {$elemMatch: {address: serviceData.email, verified: true}}})
if user?
serviceIdKey = "services." + serviceName + ".id"
update = {}
update[serviceIdKey] = serviceData.id
Meteor.users.update({
_id: user._id
}, {
$set: update
})
if serviceData.email
# Remove not verified users that have same email
notVerifiedUser = Meteor.users.remove({emails: {$elemMatch: {address: serviceData.email, verified: false}}})
# Try to get existent user with same email verified
user = Meteor.users.findOne({emails: {$elemMatch: {address: serviceData.email, verified: true}}})
if user?
serviceIdKey = "services." + serviceName + ".id"
update = {}
update[serviceIdKey] = serviceData.id
Meteor.users.update({
_id: user._id
}, {
$set: update
})
return orig_updateOrCreateUserFromExternalService.apply(this, arguments)
......@@ -41,10 +41,11 @@ Accounts.onCreateUser (options, user) ->
else
user.name = user.services[serviceName].username
user.emails = [
address: user.services[serviceName].email
verified: true
]
if user.services[serviceName].email
user.emails = [
address: user.services[serviceName].email
verified: true
]
return user
......
......@@ -36,10 +36,10 @@ usernameIsAvaliable = (username) ->
usernames.push slug service.username
if user.emails?.length > 0
for email in user.emails when email.verified is true
for email in user.emails when email.address? and email.verified is true
usernames.push slug email.address.replace(/@.+$/, '')
for email in user.emails when email.verified is true
for email in user.emails when email.address? and email.verified is true
usernames.push slug email.address.replace(/(.+)@(\w+).+/, '$1.$2')
for item in usernames
......
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