mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Refactor to use password strength options
This commit is contained in:
@@ -28,13 +28,25 @@ module.exports = AuthenticationManager =
|
||||
else
|
||||
callback null, null
|
||||
|
||||
setUserPassword: (user_id, password, callback = (error) ->) ->
|
||||
validateEmail: (email) ->
|
||||
if !email?.length
|
||||
return { message: 'email not set' }
|
||||
return null
|
||||
|
||||
validatePassword: (password) ->
|
||||
if !password?
|
||||
return { message: 'password not set' }
|
||||
if (Settings.passwordStrengthOptions?.length?.max? and
|
||||
Settings.passwordStrengthOptions?.length?.max < password.length)
|
||||
return callback("password is too long")
|
||||
return { message: 'password is too short' }
|
||||
if (Settings.passwordStrengthOptions?.length?.min? and
|
||||
Settings.passwordStrengthOptions?.length?.min > password.length)
|
||||
return callback("password is too short")
|
||||
return { message: "password is too short" }
|
||||
return null
|
||||
|
||||
setUserPassword: (user_id, password, callback = (error) ->) ->
|
||||
validation = validatePassword(password)
|
||||
return callback(validation.message) if validation?
|
||||
|
||||
bcrypt.genSalt BCRYPT_ROUNDS, (error, salt) ->
|
||||
return callback(error) if error?
|
||||
|
||||
@@ -13,20 +13,11 @@ settings = require "settings-sharelatex"
|
||||
EmailHelper = require("../Helpers/EmailHelper")
|
||||
|
||||
module.exports = UserRegistrationHandler =
|
||||
hasZeroLengths : (props) ->
|
||||
hasZeroLength = false
|
||||
props.forEach (prop) ->
|
||||
if prop.length == 0
|
||||
hasZeroLength = true
|
||||
return hasZeroLength
|
||||
|
||||
isTooShort: (prop, length) ->
|
||||
return prop.length < length
|
||||
|
||||
_registrationRequestIsValid : (body, callback)->
|
||||
email = EmailHelper.parseEmail(body.email) or ''
|
||||
password = body.password
|
||||
if @hasZeroLengths([password, email]) or @isTooShort(password, 6)
|
||||
invalidEmail = AuthenticationManager.validateEmail(email)
|
||||
invalidPassword = AuthenticationManager.validatePassword(body.password)
|
||||
if invalidEmail? or invalidPassword?
|
||||
return false
|
||||
else
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user