mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
42 lines
No EOL
1.3 KiB
CoffeeScript
42 lines
No EOL
1.3 KiB
CoffeeScript
PasswordResetHandler = require("./PasswordResetHandler")
|
|
RateLimiter = require("../../infrastructure/RateLimiter")
|
|
logger = require "logger-sharelatex"
|
|
|
|
module.exports =
|
|
|
|
renderRequestResetForm: (req, res)->
|
|
res.render "user/passwordReset",
|
|
title:"reset_password"
|
|
|
|
requestReset: (req, res)->
|
|
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")}
|
|
|
|
renderSetPasswordForm: (req, res)->
|
|
res.render "user/setPassword",
|
|
title:"set_password"
|
|
passwordResetToken:req.query.passwordResetToken
|
|
|
|
setNewUserPassword: (req, res)->
|
|
{passwordResetToken, password} = req.body
|
|
if !password? or password.length == 0 or !passwordResetToken? or passwordResetToken.length == 0
|
|
return res.send 500
|
|
PasswordResetHandler.setNewUserPassword passwordResetToken?.trim(), password?.trim(), (err)->
|
|
if err?
|
|
res.send 500
|
|
else
|
|
res.send 200 |