From 5df01acfe1136451ed8c49e9e759c76a92a75028 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 10 Apr 2014 17:26:09 +0100 Subject: [PATCH] moved reset password to new controler, not tests as it will be rewritten soon. Just want to kill off /controllers --- .../Features/User/UserController.coffee | 30 +++++++++++++++++- .../coffee/controllers/UserController.coffee | 31 ++----------------- services/web/app/coffee/router.coffee | 2 +- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/services/web/app/coffee/Features/User/UserController.coffee b/services/web/app/coffee/Features/User/UserController.coffee index d4cee5d626..6aff636f35 100644 --- a/services/web/app/coffee/Features/User/UserController.coffee +++ b/services/web/app/coffee/Features/User/UserController.coffee @@ -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" \ No newline at end of file diff --git a/services/web/app/coffee/controllers/UserController.coffee b/services/web/app/coffee/controllers/UserController.coffee index 8b9116fae8..e1a9be4460 100644 --- a/services/web/app/coffee/controllers/UserController.coffee +++ b/services/web/app/coffee/controllers/UserController.coffee @@ -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" + diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 42bc253f10..3c683b6fe2 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -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