mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Improve robustness of email validation
This commit is contained in:
parent
ed5bc70350
commit
dbd6ea30e9
2 changed files with 16 additions and 7 deletions
|
@ -4,11 +4,14 @@ TeamInvitesHandler = require('./TeamInvitesHandler')
|
||||||
AuthenticationController = require("../Authentication/AuthenticationController")
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
||||||
SubscriptionLocator = require("./SubscriptionLocator")
|
SubscriptionLocator = require("./SubscriptionLocator")
|
||||||
ErrorController = require("../Errors/ErrorController")
|
ErrorController = require("../Errors/ErrorController")
|
||||||
|
EmailHelper = require("../Helpers/EmailHelper")
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
createInvite: (req, res, next) ->
|
createInvite: (req, res, next) ->
|
||||||
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
||||||
email = req.body.email
|
email = EmailHelper.parseEmail(req.body.email)
|
||||||
|
if !email?
|
||||||
|
return res.sendStatus(400)
|
||||||
|
|
||||||
TeamInvitesHandler.createInvite teamManagerId, email, (err, invite) ->
|
TeamInvitesHandler.createInvite teamManagerId, email, (err, invite) ->
|
||||||
return next(err) if err?
|
return next(err) if err?
|
||||||
|
@ -45,8 +48,10 @@ module.exports =
|
||||||
res.sendStatus 204
|
res.sendStatus 204
|
||||||
|
|
||||||
revokeInvite: (req, res) ->
|
revokeInvite: (req, res) ->
|
||||||
email = req.params.email
|
email = EmailHelper.parseEmail(req.params.email)
|
||||||
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
teamManagerId = AuthenticationController.getLoggedInUserId(req)
|
||||||
|
if !email?
|
||||||
|
return res.sendStatus(400)
|
||||||
|
|
||||||
TeamInvitesHandler.revokeInvite teamManagerId, email, (err, results) ->
|
TeamInvitesHandler.revokeInvite teamManagerId, email, (err, results) ->
|
||||||
return next(err) if err?
|
return next(err) if err?
|
||||||
|
|
|
@ -28,6 +28,8 @@ module.exports = TeamInvitesHandler =
|
||||||
return callback(null, invite, subscription)
|
return callback(null, invite, subscription)
|
||||||
|
|
||||||
createInvite: (teamManagerId, email, callback) ->
|
createInvite: (teamManagerId, email, callback) ->
|
||||||
|
email = EmailHelper.parseEmail(email)
|
||||||
|
return callback(new Error('invalid email')) if !email?
|
||||||
logger.log {teamManagerId, email}, "Creating manager team invite"
|
logger.log {teamManagerId, email}, "Creating manager team invite"
|
||||||
UserGetter.getUser teamManagerId, (error, teamManager) ->
|
UserGetter.getUser teamManagerId, (error, teamManager) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
|
@ -45,12 +47,14 @@ module.exports = TeamInvitesHandler =
|
||||||
createInvite(subscription, email, inviterName, callback)
|
createInvite(subscription, email, inviterName, callback)
|
||||||
|
|
||||||
createDomainInvite: (user, licence, callback) ->
|
createDomainInvite: (user, licence, callback) ->
|
||||||
logger.log {licence, email: user.email}, "Creating domain team invite"
|
email = EmailHelper.parseEmail(user.email)
|
||||||
|
return callback(new Error('invalid email')) if !email?
|
||||||
|
logger.log {licence, email: email}, "Creating domain team invite"
|
||||||
inviterName = licence.name.replace(/\s+licence$/i, licence.name)
|
inviterName = licence.name.replace(/\s+licence$/i, licence.name)
|
||||||
|
|
||||||
SubscriptionLocator.getSubscription licence.subscription_id, (error, subscription) ->
|
SubscriptionLocator.getSubscription licence.subscription_id, (error, subscription) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
createInvite(subscription, user.email, inviterName, callback)
|
createInvite(subscription, email, inviterName, callback)
|
||||||
|
|
||||||
acceptInvite: (token, userId, callback) ->
|
acceptInvite: (token, userId, callback) ->
|
||||||
logger.log {userId}, "Accepting invite"
|
logger.log {userId}, "Accepting invite"
|
||||||
|
@ -64,6 +68,8 @@ module.exports = TeamInvitesHandler =
|
||||||
removeInviteFromTeam(subscription.id, invite.email, callback)
|
removeInviteFromTeam(subscription.id, invite.email, callback)
|
||||||
|
|
||||||
revokeInvite: (teamManagerId, email, callback) ->
|
revokeInvite: (teamManagerId, email, callback) ->
|
||||||
|
email = EmailHelper.parseEmail(email)
|
||||||
|
return callback(new Error('invalid email')) if !email?
|
||||||
logger.log {teamManagerId, email}, "Revoking invite"
|
logger.log {teamManagerId, email}, "Revoking invite"
|
||||||
SubscriptionLocator.getUsersSubscription teamManagerId, (err, teamSubscription) ->
|
SubscriptionLocator.getUsersSubscription teamManagerId, (err, teamSubscription) ->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
|
@ -87,7 +93,6 @@ createInvite = (subscription, email, inviterName, callback) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
return callback(reason) unless possible
|
return callback(reason) unless possible
|
||||||
|
|
||||||
email = EmailHelper.parseEmail(email)
|
|
||||||
|
|
||||||
invite = subscription.teamInvites.find (invite) -> invite.email == email
|
invite = subscription.teamInvites.find (invite) -> invite.email == email
|
||||||
|
|
||||||
|
@ -114,7 +119,6 @@ createInvite = (subscription, email, inviterName, callback) ->
|
||||||
return callback(error, invite)
|
return callback(error, invite)
|
||||||
|
|
||||||
removeInviteFromTeam = (subscriptionId, email, callback) ->
|
removeInviteFromTeam = (subscriptionId, email, callback) ->
|
||||||
email = EmailHelper.parseEmail(email)
|
|
||||||
searchConditions = { _id: new ObjectId(subscriptionId.toString()) }
|
searchConditions = { _id: new ObjectId(subscriptionId.toString()) }
|
||||||
removeInvite = { $pull: { teamInvites: { email: email } } }
|
removeInvite = { $pull: { teamInvites: { email: email } } }
|
||||||
logger.log {subscriptionId, email, searchConditions, removeInvite}, 'removeInviteFromTeam'
|
logger.log {subscriptionId, email, searchConditions, removeInvite}, 'removeInviteFromTeam'
|
||||||
|
@ -129,7 +133,7 @@ removeLegacyInvite = (subscriptionId, email, callback) ->
|
||||||
_id: new ObjectId(subscriptionId.toString())
|
_id: new ObjectId(subscriptionId.toString())
|
||||||
}, {
|
}, {
|
||||||
$pull: {
|
$pull: {
|
||||||
invited_emails: EmailHelper.parseEmail(email)
|
invited_emails: email
|
||||||
}
|
}
|
||||||
}, callback)
|
}, callback)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue