Lookup users by email hostname using new field

This commit is contained in:
hugh-obrien 2018-10-06 17:22:39 +01:00
parent 026f7eebcd
commit af3cc01496
2 changed files with 11 additions and 1 deletions

View file

@ -1,2 +1,7 @@
UserGetter = require("../User/UserGetter")
module.exports = InstitutionsController =
confirmDomain: (req, res, next = (error) ->) ->
confirmDomain: (req, res, next) ->
hostname = req.body.hostname
UserGetter.getUsersByHostname hostname, {_id:1, emails:1}, (error, users) ->
res.json {hostname: hostname, wub: users}

View file

@ -58,6 +58,11 @@ module.exports = UserGetter =
# well
@getUserByMainEmail email, projection, callback
getUsersByHostname: (hostname, projection, callback = (error, users) ->) ->
hostname = hostname.trim()
query = emails: { $exists: true }, 'emails.hostname': hostname
db.users.find query, projection, callback
getUsers: (user_ids, projection, callback = (error, users) ->) ->
try
user_ids = user_ids.map (u) -> ObjectId(u.toString())