mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05: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 =
|
||||
|
||||
parseEmail: (email) ->
|
||||
email = mimelib.parseAddresses(email or "")[0]?.address?.toLowerCase()
|
||||
if !email? or email == ""
|
||||
return null
|
||||
else
|
||||
return email
|
||||
return null unless email?
|
||||
email = email.trim().toLowerCase()
|
||||
|
||||
matched = email.match EMAIL_REGEXP
|
||||
return null unless matched? && matched[0]?
|
||||
|
||||
matched[0]
|
||||
|
|
|
@ -11,12 +11,9 @@ EmailHandler = require("../Email/EmailHandler")
|
|||
OneTimeTokenHandler = require "../Security/OneTimeTokenHandler"
|
||||
Analytics = require "../Analytics/AnalyticsManager"
|
||||
settings = require "settings-sharelatex"
|
||||
EmailHelper = require("../Helpers/EmailHelper")
|
||||
|
||||
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) ->
|
||||
hasZeroLength = false
|
||||
props.forEach (prop) ->
|
||||
|
@ -25,13 +22,10 @@ module.exports = UserRegistrationHandler =
|
|||
return hasZeroLength
|
||||
|
||||
_registrationRequestIsValid : (body, callback)->
|
||||
email = sanitize.escape(body.email).trim().toLowerCase()
|
||||
email = EmailHelper.parseEmail(body.email) or ''
|
||||
password = body.password
|
||||
username = email.match(/^[^@]*/)
|
||||
if @hasZeroLengths([password, email])
|
||||
return false
|
||||
else if !@validateEmail(email)
|
||||
return false
|
||||
else
|
||||
return true
|
||||
|
||||
|
@ -47,7 +41,7 @@ module.exports = UserRegistrationHandler =
|
|||
requestIsValid = @_registrationRequestIsValid userDetails
|
||||
if !requestIsValid
|
||||
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) =>
|
||||
if err?
|
||||
return callback err
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
"marked": "^0.3.5",
|
||||
"method-override": "^2.3.3",
|
||||
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1",
|
||||
"mimelib": "0.2.14",
|
||||
"mocha": "^5.0.1",
|
||||
"mongojs": "2.4.0",
|
||||
"mongoose": "4.11.4",
|
||||
|
|
|
@ -5,6 +5,7 @@ path = require('path')
|
|||
modulePath = path.join __dirname, '../../../../app/js/Features/User/UserRegistrationHandler'
|
||||
sinon = require("sinon")
|
||||
expect = require("chai").expect
|
||||
EmailHelper = require '../../../../app/js/Features/Helpers/EmailHelper'
|
||||
|
||||
describe "UserRegistrationHandler", ->
|
||||
|
||||
|
@ -37,6 +38,7 @@ describe "UserRegistrationHandler", ->
|
|||
"../Security/OneTimeTokenHandler": @OneTimeTokenHandler
|
||||
"../Analytics/AnalyticsManager": @AnalyticsManager = { recordEvent: sinon.stub() }
|
||||
"settings-sharelatex": @settings = {siteUrl: "http://sl.example.com"}
|
||||
"../Helpers/EmailHelper": EmailHelper
|
||||
|
||||
@passingRequest = {email:"something@email.com", password:"123"}
|
||||
|
||||
|
|
Loading…
Reference in a new issue