From c4a420bd7fe2727aa45a40fd22912fb0dea2b39f Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 16 May 2014 17:29:54 +0100 Subject: [PATCH] writen function to set the user email safely --- .../app/coffee/Features/User/UserUpdater.coffee | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/web/app/coffee/Features/User/UserUpdater.coffee b/services/web/app/coffee/Features/User/UserUpdater.coffee index f6c281ea81..71a761a8e2 100644 --- a/services/web/app/coffee/Features/User/UserUpdater.coffee +++ b/services/web/app/coffee/Features/User/UserUpdater.coffee @@ -1,6 +1,7 @@ mongojs = require("../../infrastructure/mongojs") db = mongojs.db ObjectId = mongojs.ObjectId +UserLocator = require("./UserLocator") module.exports = UserUpdater = updateUser: (query, update, callback = (error) ->) -> @@ -10,3 +11,17 @@ module.exports = UserUpdater = query = _id: query db.users.update query, update, callback + + + changeEmailAddress: (user_id, newEmail, callback)-> + self = @ + UserLocator.findById user_id, (error, user) -> + if user? + return callback({message:"User with that email already exists."}) + self.updateUser user_id.toString(), { + $set: { "email": newEmail}, + }, (err) -> + if err? + return callback(err) + callback() +