diff --git a/services/web/app/coffee/Features/Authentication/AuthenticationManager.coffee b/services/web/app/coffee/Features/Authentication/AuthenticationManager.coffee index 49bd994b2c..26c31de84c 100644 --- a/services/web/app/coffee/Features/Authentication/AuthenticationManager.coffee +++ b/services/web/app/coffee/Features/Authentication/AuthenticationManager.coffee @@ -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? diff --git a/services/web/app/coffee/Features/User/UserRegistrationHandler.coffee b/services/web/app/coffee/Features/User/UserRegistrationHandler.coffee index 0928f64640..1fa1dc0d79 100644 --- a/services/web/app/coffee/Features/User/UserRegistrationHandler.coffee +++ b/services/web/app/coffee/Features/User/UserRegistrationHandler.coffee @@ -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