overleaf/services/web/app/coffee/Features/PasswordReset/PasswordResetController.coffee

40 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2014-05-15 15:50:38 +00:00
PasswordResetHandler = require("./PasswordResetHandler")
RateLimiter = require("../../infrastructure/RateLimiter")
2014-05-15 15:20:23 +00:00
module.exports =
2014-05-15 15:50:38 +00:00
renderRequestResetForm: (req, res)->
res.render "user/passwordReset",
title:"Reset Password"
2014-05-15 15:20:23 +00:00
2014-05-15 15:50:38 +00:00
requestReset: (req, res)->
2014-06-10 16:54:29 +00:00
email = req.body.email.trim().toLowerCase()
opts =
endpointName:"auto_compile"
timeInterval:60
subjectName:email
throttle: 3
RateLimiter.addCount opts, (err, canCompile)->
if !canCompile
return res.send 500
PasswordResetHandler.generateAndEmailResetToken email, (err)->
if err?
res.send 500, {message:err?.message}
else
res.send 200
2014-05-15 15:20:23 +00:00
2014-05-15 15:50:38 +00:00
renderSetPasswordForm: (req, res)->
res.render "user/setPassword",
title:"Set Password"
passwordResetToken:req.query.passwordResetToken
2014-05-15 15:20:23 +00:00
2014-05-15 15:50:38 +00:00
setNewUserPassword: (req, res)->
{passwordResetToken, password} = req.body
if !password? or password.length == 0 or !passwordResetToken? or passwordResetToken.length == 0
2014-05-15 15:50:38 +00:00
return res.send 500
PasswordResetHandler.setNewUserPassword passwordResetToken?.trim(), password?.trim(), (err)->
2014-05-15 15:50:38 +00:00
if err?
res.send 500
else
res.send 200