writen function to set the user email safely

This commit is contained in:
Henry Oswald 2014-05-16 17:29:54 +01:00
parent a62bff5052
commit c4a420bd7f

View file

@ -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()