mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-09 17:52:13 +00:00
use EmailHelper.parseEmail on registration
Also changed EmailHelper to use the regexp already used in UserRegistrationHandler rather than the `mimelib` package as it is deprecated.
This commit is contained in:
parent
e614ed9248
commit
97c145433e
4 changed files with 13 additions and 17 deletions
|
@ -1,11 +1,12 @@
|
||||||
mimelib = require("mimelib")
|
EMAIL_REGEXP = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||||
|
|
||||||
|
|
||||||
module.exports = EmailHelper =
|
module.exports = EmailHelper =
|
||||||
|
|
||||||
parseEmail: (email) ->
|
parseEmail: (email) ->
|
||||||
email = mimelib.parseAddresses(email or "")[0]?.address?.toLowerCase()
|
return null unless email?
|
||||||
if !email? or email == ""
|
email = email.trim().toLowerCase()
|
||||||
return null
|
|
||||||
else
|
matched = email.match EMAIL_REGEXP
|
||||||
return email
|
return null unless matched? && matched[0]?
|
||||||
|
|
||||||
|
matched[0]
|
||||||
|
|
|
@ -11,12 +11,9 @@ EmailHandler = require("../Email/EmailHandler")
|
||||||
OneTimeTokenHandler = require "../Security/OneTimeTokenHandler"
|
OneTimeTokenHandler = require "../Security/OneTimeTokenHandler"
|
||||||
Analytics = require "../Analytics/AnalyticsManager"
|
Analytics = require "../Analytics/AnalyticsManager"
|
||||||
settings = require "settings-sharelatex"
|
settings = require "settings-sharelatex"
|
||||||
|
EmailHelper = require("../Helpers/EmailHelper")
|
||||||
|
|
||||||
module.exports = UserRegistrationHandler =
|
module.exports = UserRegistrationHandler =
|
||||||
validateEmail : (email) ->
|
|
||||||
re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
||||||
return re.test(email)
|
|
||||||
|
|
||||||
hasZeroLengths : (props) ->
|
hasZeroLengths : (props) ->
|
||||||
hasZeroLength = false
|
hasZeroLength = false
|
||||||
props.forEach (prop) ->
|
props.forEach (prop) ->
|
||||||
|
@ -25,13 +22,10 @@ module.exports = UserRegistrationHandler =
|
||||||
return hasZeroLength
|
return hasZeroLength
|
||||||
|
|
||||||
_registrationRequestIsValid : (body, callback)->
|
_registrationRequestIsValid : (body, callback)->
|
||||||
email = sanitize.escape(body.email).trim().toLowerCase()
|
email = EmailHelper.parseEmail(body.email) or ''
|
||||||
password = body.password
|
password = body.password
|
||||||
username = email.match(/^[^@]*/)
|
|
||||||
if @hasZeroLengths([password, email])
|
if @hasZeroLengths([password, email])
|
||||||
return false
|
return false
|
||||||
else if !@validateEmail(email)
|
|
||||||
return false
|
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
@ -47,7 +41,7 @@ module.exports = UserRegistrationHandler =
|
||||||
requestIsValid = @_registrationRequestIsValid userDetails
|
requestIsValid = @_registrationRequestIsValid userDetails
|
||||||
if !requestIsValid
|
if !requestIsValid
|
||||||
return callback(new Error("request is not valid"))
|
return callback(new Error("request is not valid"))
|
||||||
userDetails.email = userDetails.email?.trim()?.toLowerCase()
|
userDetails.email = EmailHelper.parseEmail(userDetails.email)
|
||||||
UserGetter.getUserByAnyEmail userDetails.email, (err, user) =>
|
UserGetter.getUserByAnyEmail userDetails.email, (err, user) =>
|
||||||
if err?
|
if err?
|
||||||
return callback err
|
return callback err
|
||||||
|
|
|
@ -62,7 +62,6 @@
|
||||||
"marked": "^0.3.5",
|
"marked": "^0.3.5",
|
||||||
"method-override": "^2.3.3",
|
"method-override": "^2.3.3",
|
||||||
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1",
|
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1",
|
||||||
"mimelib": "0.2.14",
|
|
||||||
"mocha": "^5.0.1",
|
"mocha": "^5.0.1",
|
||||||
"mongojs": "2.4.0",
|
"mongojs": "2.4.0",
|
||||||
"mongoose": "4.11.4",
|
"mongoose": "4.11.4",
|
||||||
|
|
|
@ -5,6 +5,7 @@ path = require('path')
|
||||||
modulePath = path.join __dirname, '../../../../app/js/Features/User/UserRegistrationHandler'
|
modulePath = path.join __dirname, '../../../../app/js/Features/User/UserRegistrationHandler'
|
||||||
sinon = require("sinon")
|
sinon = require("sinon")
|
||||||
expect = require("chai").expect
|
expect = require("chai").expect
|
||||||
|
EmailHelper = require '../../../../app/js/Features/Helpers/EmailHelper'
|
||||||
|
|
||||||
describe "UserRegistrationHandler", ->
|
describe "UserRegistrationHandler", ->
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ describe "UserRegistrationHandler", ->
|
||||||
"../Security/OneTimeTokenHandler": @OneTimeTokenHandler
|
"../Security/OneTimeTokenHandler": @OneTimeTokenHandler
|
||||||
"../Analytics/AnalyticsManager": @AnalyticsManager = { recordEvent: sinon.stub() }
|
"../Analytics/AnalyticsManager": @AnalyticsManager = { recordEvent: sinon.stub() }
|
||||||
"settings-sharelatex": @settings = {siteUrl: "http://sl.example.com"}
|
"settings-sharelatex": @settings = {siteUrl: "http://sl.example.com"}
|
||||||
|
"../Helpers/EmailHelper": EmailHelper
|
||||||
|
|
||||||
@passingRequest = {email:"something@email.com", password:"123"}
|
@passingRequest = {email:"something@email.com", password:"123"}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue