overleaf/services/web/app/coffee/Features/PasswordReset/PasswordResetHandler.coffee
Henry Oswald 9419d3a0e5 hooked up the frount end ui to show the email can not be found,
added client side valdidation on password, removed server side min
length check. Just check that it is not 0 len
2014-05-16 11:26:29 +01:00

30 lines
No EOL
1.3 KiB
CoffeeScript

settings = require("settings-sharelatex")
async = require("async")
UserGetter = require("../User/UserGetter")
PasswordResetTokenHandler = require("./PasswordResetTokenHandler")
EmailHandler = require("../Email/EmailHandler")
AuthenticationManager = require("../Authentication/AuthenticationManager")
logger = require("logger-sharelatex")
module.exports =
generateAndEmailResetToken:(email, callback)->
UserGetter.getUser email:email, (err, user)->
if err then return callback(err)
if !user?
logger.err email:email, "user could not be found for password reset"
return callback(message:"Can't find that email, sorry.")
PasswordResetTokenHandler.getNewToken user._id, (err, token)->
if err then return callback(err)
emailOptions =
to : email
setNewPasswordUrl : "#{settings.siteUrl}/user/password/set?passwordResetToken=#{token}"
EmailHandler.sendEmail "passwordResetRequested", emailOptions, callback
setNewUserPassword: (token, password, callback)->
PasswordResetTokenHandler.getUserIdFromTokenAndExpire token, (err, user_id)->
if err then return callback(err)
if !user_id?
logger.err user_id:user_id, "token for password reset did not find user_id"
return callback("no user found")
AuthenticationManager.setUserPassword user_id, password, callback