Refactor to validate in AuthenticationManager

This commit is contained in:
Alasdair Smith 2018-10-04 13:47:53 +01:00
parent 44c86b3769
commit 676557a051
2 changed files with 7 additions and 6 deletions

View file

@ -3,6 +3,7 @@ User = require("../../models/User").User
{db, ObjectId} = require("../../infrastructure/mongojs")
crypto = require 'crypto'
bcrypt = require 'bcrypt'
EmailHelper = require("../Helpers/EmailHelper")
BCRYPT_ROUNDS = Settings?.security?.bcryptRounds or 12
@ -29,8 +30,9 @@ module.exports = AuthenticationManager =
callback null, null
validateEmail: (email) ->
if !email?.length
return { message: 'email not set' }
parsed = EmailHelper.parseEmail(email)
if !parsed?
return { message: 'email not valid' }
return null
validatePassword: (password) ->
@ -45,7 +47,7 @@ module.exports = AuthenticationManager =
return null
setUserPassword: (user_id, password, callback = (error) ->) ->
validation = validatePassword(password)
validation = @validatePassword(password)
return callback(validation.message) if validation?
bcrypt.genSalt BCRYPT_ROUNDS, (error, salt) ->

View file

@ -14,9 +14,8 @@ EmailHelper = require("../Helpers/EmailHelper")
module.exports = UserRegistrationHandler =
_registrationRequestIsValid : (body, callback)->
email = EmailHelper.parseEmail(body.email) or ''
invalidEmail = AuthenticationManager.validateEmail(email)
invalidPassword = AuthenticationManager.validatePassword(body.password)
invalidEmail = AuthenticationManager.validateEmail(body.email or '')
invalidPassword = AuthenticationManager.validatePassword(body.password or '')
if invalidEmail? or invalidPassword?
return false
else