mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
41 lines
No EOL
1.2 KiB
CoffeeScript
41 lines
No EOL
1.2 KiB
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:"User with that email already exists."})
|
|
self.updateUser user_id.toString(), {
|
|
$set: { "email": newEmail},
|
|
}, (err) ->
|
|
if err?
|
|
logger.err err:err, "problem updating users email"
|
|
return callback(err)
|
|
callback()
|
|
|
|
|
|
updatePersonalInfo: (user_id, info, callback)->
|
|
self = @
|
|
update =
|
|
$set:
|
|
"first_name": info.first_name || ""
|
|
"last_name": info.last_name || ""
|
|
"role": info.role || ""
|
|
"institution": info.institution || ""
|
|
self.updateUser user_id.toString(), update, (err)->
|
|
callback(err) |