2014-05-15 11:50:38 -04:00
|
|
|
PasswordResetHandler = require("./PasswordResetHandler")
|
2014-05-16 05:31:33 -04:00
|
|
|
RateLimiter = require("../../infrastructure/RateLimiter")
|
|
|
|
|
2014-05-15 11:20:23 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
2014-05-15 11:50:38 -04:00
|
|
|
renderRequestResetForm: (req, res)->
|
|
|
|
res.render "user/passwordReset",
|
|
|
|
title:"Reset Password"
|
2014-05-15 11:20:23 -04:00
|
|
|
|
2014-05-15 11:50:38 -04:00
|
|
|
requestReset: (req, res)->
|
|
|
|
email = req.body.email.trim()
|
2014-05-16 05:31:33 -04:00
|
|
|
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?
|
2014-05-16 06:04:48 -04:00
|
|
|
res.send 500, {message:err?.message}
|
2014-05-16 05:31:33 -04:00
|
|
|
else
|
|
|
|
res.send 200
|
2014-05-15 11:20:23 -04:00
|
|
|
|
2014-05-15 11:50:38 -04:00
|
|
|
renderSetPasswordForm: (req, res)->
|
|
|
|
res.render "user/setPassword",
|
|
|
|
title:"Set Password"
|
2014-05-15 12:16:20 -04:00
|
|
|
passwordResetToken:req.query.passwordResetToken
|
2014-05-15 11:20:23 -04:00
|
|
|
|
2014-05-15 11:50:38 -04:00
|
|
|
setNewUserPassword: (req, res)->
|
2014-05-15 12:16:20 -04:00
|
|
|
{passwordResetToken, password} = req.body
|
2014-05-16 06:04:48 -04:00
|
|
|
if !password? or password.length == 0 or !passwordResetToken? or passwordResetToken.length == 0
|
2014-05-15 11:50:38 -04:00
|
|
|
return res.send 500
|
2014-05-15 12:16:20 -04:00
|
|
|
PasswordResetHandler.setNewUserPassword passwordResetToken?.trim(), password?.trim(), (err)->
|
2014-05-15 11:50:38 -04:00
|
|
|
if err?
|
|
|
|
res.send 500
|
|
|
|
else
|
|
|
|
res.send 200
|