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

43 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2014-05-15 11:50:38 -04:00
PasswordResetHandler = require("./PasswordResetHandler")
RateLimiter = require("../../infrastructure/RateLimiter")
logger = require "logger-sharelatex"
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",
2014-08-01 08:47:14 -04:00
title:"reset_password"
2014-05-15 11:20:23 -04:00
2014-05-15 11:50:38 -04:00
requestReset: (req, res)->
2014-06-10 12:54:29 -04:00
email = req.body.email.trim().toLowerCase()
opts =
endpointName: "password_reset_rate_limit"
timeInterval: 60
subjectName: req.ip
throttle: 6
RateLimiter.addCount opts, (err, canCompile)->
if !canCompile
return res.send 500, { message: req.i18n.translate("rate_limit_hit_wait")}
PasswordResetHandler.generateAndEmailResetToken email, (err, exists)->
if err?
res.send 500, {message:err?.message}
else if exists
res.send 200
else
res.send 404, {message: req.i18n.translate("cant_find_email")}
2014-05-15 11:20:23 -04:00
2014-05-15 11:50:38 -04:00
renderSetPasswordForm: (req, res)->
res.render "user/setPassword",
2014-08-01 08:47:14 -04:00
title:"set_password"
passwordResetToken:req.query.passwordResetToken
2014-05-15 11:20:23 -04:00
2014-05-15 11:50:38 -04:00
setNewUserPassword: (req, res)->
{passwordResetToken, password} = req.body
if !password? or password.length == 0 or !passwordResetToken? or passwordResetToken.length == 0
return res.send 400
PasswordResetHandler.setNewUserPassword passwordResetToken?.trim(), password?.trim(), (err, found) ->
return next(err) if err?
if found
res.send 200
2014-05-15 11:50:38 -04:00
else
res.send 404, {message: req.i18n.translate("password_reset_token_expired")}