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:
Henry Oswald 2014-04-10 17:26:09 +01:00
parent 5760e51d6e
commit 5df01acfe1
3 changed files with 33 additions and 30 deletions

View file

@ -10,7 +10,6 @@ Url = require("url")
AuthenticationController = require("../Authentication/AuthenticationController")
AuthenticationManager = require("../Authentication/AuthenticationManager")
module.exports =
deleteUser: (req, res)->
@ -99,3 +98,32 @@ module.exports =
message:
type:'error'
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"

View file

@ -14,41 +14,16 @@ AuthenticationController = require("../Features/Authentication/AuthenticationCon
SubscriptionLocator = require("../Features/Subscription/SubscriptionLocator")
UserDeleter = require("../Features/User/UserDeleter")
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"

View file

@ -79,7 +79,7 @@ module.exports = class Router
app.post '/user/settings', AuthenticationController.requireLogin(), UserController_new.updateUserSettings
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController_new.changePassword
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', AuthenticationController.requireLogin(), UserController_new.deleteUser