overleaf/services/web/app/coffee/Features/User/UserUpdater.coffee
Henry Oswald d047d44079 Changed the error messages which are sent down to the client to be translated first
fixed up tests from titles we check when rendering, deleted them as they never
catch anything important, more hastle than they are worth imo.
2014-08-01 14:03:38 +01:00

30 lines
878 B
CoffeeScript

logger = require("logger-sharelatex")
mongojs = require("../../infrastructure/mongojs")
db = mongojs.db
ObjectId = mongojs.ObjectId
UserLocator = require("./UserLocator")
module.exports = UserUpdater =
updateUser: (query, update, callback = (error) ->) ->
if typeof query == "string"
query = _id: ObjectId(query)
else if query instanceof ObjectId
query = _id: query
db.users.update query, update, callback
changeEmailAddress: (user_id, newEmail, callback)->
self = @
logger.log user_id:user_id, newEmail:newEmail, "updaing email address of user"
UserLocator.findByEmail newEmail, (error, user) ->
if user?
return callback({message:"alread_exists"})
self.updateUser user_id.toString(), {
$set: { "email": newEmail},
}, (err) ->
if err?
logger.err err:err, "problem updating users email"
return callback(err)
callback()