mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
bbaca91e57
Use only that method to find users by email.
33 lines
1,002 B
CoffeeScript
33 lines
1,002 B
CoffeeScript
logger = require("logger-sharelatex")
|
|
mongojs = require("../../infrastructure/mongojs")
|
|
metrics = require("metrics-sharelatex")
|
|
db = mongojs.db
|
|
ObjectId = mongojs.ObjectId
|
|
UserGetter = require("./UserGetter")
|
|
|
|
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"
|
|
UserGetter.getUserByMainEmail 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()
|
|
|
|
|
|
metrics.timeAsyncMethod UserUpdater, 'updateUser', 'mongo.UserUpdater', logger
|