Просмотр исходного кода

Refactor to validate in AuthenticationManager

Alasdair Smith 8 лет назад
Родитель
Сommit
676557a051

+ 5 - 3
services/web/app/coffee/Features/Authentication/AuthenticationManager.coffee

@@ -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) ->

+ 2 - 3
services/web/app/coffee/Features/User/UserRegistrationHandler.coffee

@@ -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