Switched new files to .js instead of .coffee;pull/1962/head
parent
07141ff9d9
commit
22661cbb26
@ -1,2 +0,0 @@ |
||||
RocketChat.checkEmailAvailability = (email) -> |
||||
return not Meteor.users.findOne({ "emails.address": { $regex : new RegExp("^" + s.trim(s.escapeRegExp(email)) + "$", "i") } }) |
||||
@ -0,0 +1,3 @@ |
||||
RocketChat.checkEmailAvailability = function(email) { |
||||
return !Meteor.users.findOne({ "emails.address": { $regex : new RegExp("^" + s.trim(s.escapeRegExp(email)) + "$", "i") } }) |
||||
} |
||||
@ -1,26 +0,0 @@ |
||||
RocketChat._setEmail = (userId, email) -> |
||||
email = s.trim email |
||||
if not userId or not email |
||||
return false |
||||
|
||||
emailValidation = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ |
||||
if not emailValidation.test email |
||||
return false |
||||
|
||||
user = RocketChat.models.Users.findOneById userId |
||||
|
||||
# User already has desired username, return |
||||
if user.emails?[0]?.address is email |
||||
return user |
||||
|
||||
# Check e-mail availability |
||||
unless RocketChat.checkEmailAvailability email |
||||
return false |
||||
|
||||
# Set new email |
||||
RocketChat.models.Users.setEmail user._id, email |
||||
user.email = email |
||||
return user |
||||
|
||||
RocketChat.setEmail = RocketChat.RateLimiter.limitFunction RocketChat._setEmail, 1, 60000, |
||||
0: (userId) -> return not RocketChat.authz.hasPermission(userId, 'edit-other-user-info') # Administrators have permission to change others emails, so don't limit those |
||||
@ -0,0 +1,36 @@ |
||||
RocketChat._setEmail = function(userId, email) { |
||||
email = s.trim(email) |
||||
if (!userId) { |
||||
throw new Meteor.Error('invalid-user', "[methods] setEmail -> Invalid user"); |
||||
} |
||||
|
||||
if (!email) { |
||||
throw new Meteor.Error('invalid-email', "[methods] setEmail -> Invalid email"); |
||||
} |
||||
|
||||
emailValidation = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; |
||||
if (!emailValidation.test(email)) { |
||||
throw new Meteor.Error('email-invalid', "#{email} is not a valid e-mail"); |
||||
} |
||||
|
||||
user = RocketChat.models.Users.findOneById(userId); |
||||
|
||||
// User already has desired username, return
|
||||
if (user.emails && user.emails[0] && user.emails[0].address === email) { |
||||
return user; |
||||
} |
||||
|
||||
// Check e-mail availability
|
||||
if (!RocketChat.checkEmailAvailability(email)) { |
||||
throw new Meteor.Error('email-unavailable', "#{email} is already in use :("); |
||||
} |
||||
|
||||
// Set new email
|
||||
RocketChat.models.Users.setEmail(user._id, email); |
||||
user.email = email; |
||||
return user; |
||||
} |
||||
|
||||
RocketChat.setEmail = RocketChat.RateLimiter.limitFunction(RocketChat._setEmail, 1, 60000, { |
||||
0: function(userId) { return !RocketChat.authz.hasPermission(userId, 'edit-other-user-info') } // Administrators have permission to change others emails, so don't limit those
|
||||
}); |
||||
@ -1,27 +0,0 @@ |
||||
Meteor.methods |
||||
setEmail: (email) -> |
||||
if not Meteor.userId() |
||||
throw new Meteor.Error('invalid-user', "[methods] setEmail -> Invalid user") |
||||
|
||||
user = Meteor.user() |
||||
|
||||
if not RocketChat.settings.get("Accounts_AllowEmailChange") |
||||
throw new Meteor.Error(403, "[methods] setEmail -> E-mail change not allowed") |
||||
|
||||
if user.emails?[0]?.address is email |
||||
return email |
||||
|
||||
emailValidation = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ |
||||
if not emailValidation.test email |
||||
throw new Meteor.Error 'email-invalid', "#{email} is not a valid e-mail" |
||||
|
||||
if not RocketChat.checkEmailAvailability email |
||||
throw new Meteor.Error 'email-unavailable', "#{email} is already in use :(" |
||||
|
||||
unless RocketChat.setEmail user._id, email |
||||
throw new Meteor.Error 'could-not-change-email', "Could not change email" |
||||
|
||||
return email |
||||
|
||||
RocketChat.RateLimiter.limitMethod 'setEmail', 1, 1000, |
||||
userId: (userId) -> return true |
||||
@ -0,0 +1,36 @@ |
||||
Meteor.methods({ |
||||
setEmail: function(email) { |
||||
if (!Meteor.userId()) { |
||||
throw new Meteor.Error('invalid-user', "[methods] setEmail -> Invalid user"); |
||||
} |
||||
|
||||
user = Meteor.user(); |
||||
|
||||
if (!RocketChat.settings.get("Accounts_AllowEmailChange")) { |
||||
throw new Meteor.Error(403, "[methods] setEmail -> E-mail change not allowed"); |
||||
} |
||||
|
||||
if (user.emails && user.emails[0] && user.emails[0].address === email) { |
||||
return email; |
||||
} |
||||
|
||||
emailValidation = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; |
||||
if (!emailValidation.test(email)) { |
||||
throw new Meteor.Error('email-invalid', "#{email} is not a valid e-mail"); |
||||
} |
||||
|
||||
if (!RocketChat.checkEmailAvailability(email)) { |
||||
throw new Meteor.Error('email-unavailable', "#{email} is already in use :("); |
||||
} |
||||
|
||||
if (!RocketChat.setEmail(user._id, email)) { |
||||
throw new Meteor.Error('could-not-change-email', "Could not change email"); |
||||
} |
||||
|
||||
return email; |
||||
} |
||||
}); |
||||
|
||||
RocketChat.RateLimiter.limitMethod('setEmail', 1, 1000, { |
||||
userId: function(userId) { return true } |
||||
}); |
||||
Loading…
Reference in new issue