mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
writen function to set the user email safely
This commit is contained in:
parent
a62bff5052
commit
c4a420bd7f
1 changed files with 15 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
mongojs = require("../../infrastructure/mongojs")
|
mongojs = require("../../infrastructure/mongojs")
|
||||||
db = mongojs.db
|
db = mongojs.db
|
||||||
ObjectId = mongojs.ObjectId
|
ObjectId = mongojs.ObjectId
|
||||||
|
UserLocator = require("./UserLocator")
|
||||||
|
|
||||||
module.exports = UserUpdater =
|
module.exports = UserUpdater =
|
||||||
updateUser: (query, update, callback = (error) ->) ->
|
updateUser: (query, update, callback = (error) ->) ->
|
||||||
|
@ -10,3 +11,17 @@ module.exports = UserUpdater =
|
||||||
query = _id: query
|
query = _id: query
|
||||||
|
|
||||||
db.users.update query, update, callback
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue