mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
moved reset password to new controler, not tests as it will be rewritten soon. Just want to kill off /controllers
This commit is contained in:
parent
5760e51d6e
commit
5df01acfe1
3 changed files with 33 additions and 30 deletions
|
@ -10,7 +10,6 @@ Url = require("url")
|
||||||
AuthenticationController = require("../Authentication/AuthenticationController")
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
||||||
AuthenticationManager = require("../Authentication/AuthenticationManager")
|
AuthenticationManager = require("../Authentication/AuthenticationManager")
|
||||||
|
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
deleteUser: (req, res)->
|
deleteUser: (req, res)->
|
||||||
|
@ -99,3 +98,32 @@ module.exports =
|
||||||
message:
|
message:
|
||||||
type:'error'
|
type:'error'
|
||||||
text:'Your old password is wrong'
|
text:'Your old password is wrong'
|
||||||
|
|
||||||
|
|
||||||
|
doRequestPasswordReset : (req, res, next = (error) ->)->
|
||||||
|
uuid = require("node-uuid")
|
||||||
|
EmailHandler = require("../Email/EmailHandler")
|
||||||
|
email = sanitize.escape(req.body.email)
|
||||||
|
email = sanitize.escape(email).trim()
|
||||||
|
email = email.toLowerCase()
|
||||||
|
logger.log email: email, "password reset requested"
|
||||||
|
User.findOne {'email':email}, (err, user)->
|
||||||
|
if(user?)
|
||||||
|
randomPassword = uuid.v4()
|
||||||
|
AuthenticationManager.setUserPassword user._id, randomPassword, (error) ->
|
||||||
|
emailOpts =
|
||||||
|
newPassword: randomPassword
|
||||||
|
to: user.email
|
||||||
|
EmailHandler.sendEmail "passwordReset", emailOpts, (err)->
|
||||||
|
if err?
|
||||||
|
logger.err err:err, emailOpts:emailOpts, "problem sending password reset email"
|
||||||
|
return res.send 500
|
||||||
|
metrics.inc "user.password-reset"
|
||||||
|
res.send message:
|
||||||
|
text:'An email with your new password has been sent to you'
|
||||||
|
type:'success'
|
||||||
|
else
|
||||||
|
res.send message:
|
||||||
|
text:'This email address has not been registered with us'
|
||||||
|
type:'failure'
|
||||||
|
logger.info email: email, "no user found with email"
|
|
@ -14,41 +14,16 @@ AuthenticationController = require("../Features/Authentication/AuthenticationCon
|
||||||
SubscriptionLocator = require("../Features/Subscription/SubscriptionLocator")
|
SubscriptionLocator = require("../Features/Subscription/SubscriptionLocator")
|
||||||
UserDeleter = require("../Features/User/UserDeleter")
|
UserDeleter = require("../Features/User/UserDeleter")
|
||||||
EmailHandler = require("../Features/Email/EmailHandler")
|
EmailHandler = require("../Features/Email/EmailHandler")
|
||||||
Url = require("url")
|
|
||||||
uuid = require("node-uuid")
|
|
||||||
|
|
||||||
module.exports =
|
|
||||||
|
module.exports = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
doRequestPasswordReset : (req, res, next = (error) ->)->
|
|
||||||
email = sanitize.escape(req.body.email)
|
|
||||||
email = sanitize.escape(email).trim()
|
|
||||||
email = email.toLowerCase()
|
|
||||||
logger.log email: email, "password reset requested"
|
|
||||||
User.findOne {'email':email}, (err, user)->
|
|
||||||
if(user?)
|
|
||||||
randomPassword = uuid.v4()
|
|
||||||
AuthenticationManager.setUserPassword user._id, randomPassword, (error) ->
|
|
||||||
emailOpts =
|
|
||||||
newPassword: randomPassword
|
|
||||||
to: user.email
|
|
||||||
EmailHandler.sendEmail "passwordReset", emailOpts, (err)->
|
|
||||||
if err?
|
|
||||||
logger.err err:err, emailOpts:emailOpts, "problem sending password reset email"
|
|
||||||
return res.send 500
|
|
||||||
metrics.inc "user.password-reset"
|
|
||||||
res.send message:
|
|
||||||
text:'An email with your new password has been sent to you'
|
|
||||||
type:'success'
|
|
||||||
else
|
|
||||||
res.send message:
|
|
||||||
text:'This email address has not been registered with us'
|
|
||||||
type:'failure'
|
|
||||||
logger.info email: email, "no user found with email"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ module.exports = class Router
|
||||||
app.post '/user/settings', AuthenticationController.requireLogin(), UserController_new.updateUserSettings
|
app.post '/user/settings', AuthenticationController.requireLogin(), UserController_new.updateUserSettings
|
||||||
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController_new.changePassword
|
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController_new.changePassword
|
||||||
app.get '/user/passwordreset', UserPagesController.passwordResetPage
|
app.get '/user/passwordreset', UserPagesController.passwordResetPage
|
||||||
app.post '/user/passwordReset', UserController.doRequestPasswordReset
|
app.post '/user/passwordReset', UserController_new.doRequestPasswordReset
|
||||||
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController_new.unsubscribe
|
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController_new.unsubscribe
|
||||||
app.del '/user', AuthenticationController.requireLogin(), UserController_new.deleteUser
|
app.del '/user', AuthenticationController.requireLogin(), UserController_new.deleteUser
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue