overleaf/services/web/app/coffee/Features/User/UserInfoController.coffee

40 lines
1.6 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
UserGetter = require "./UserGetter"
logger = require("logger-sharelatex")
UserDeleter = require("./UserDeleter")
UserUpdater = require("./UserUpdater")
sanitize = require('sanitizer')
2016-09-22 06:33:38 -04:00
AuthenticationController = require('../Authentication/AuthenticationController')
2014-02-12 05:23:40 -05:00
module.exports = UserController =
getLoggedInUsersPersonalInfo: (req, res, next = (error) ->) ->
2016-09-22 06:33:38 -04:00
user_id = AuthenticationController.getLoggedInUserId(req)
logger.log user_id: user_id, "reciving request for getting logged in users personal info"
return next(new Error("User is not logged in")) if !user_id?
UserGetter.getUser user_id, {
first_name: true, last_name: true,
role:true, institution:true,
email: true, signUpDate: true
}, (error, user) ->
return next(error) if error?
2014-06-11 12:45:09 -04:00
UserController.sendFormattedPersonalInfo(user, res, next)
2014-02-12 05:23:40 -05:00
getPersonalInfo: (req, res, next = (error) ->) ->
2014-06-11 12:45:09 -04:00
UserGetter.getUser req.params.user_id, { _id: true, first_name: true, last_name: true, email: true}, (error, user) ->
logger.log user_id: req.params.user_id, "reciving request for getting users personal info"
2014-02-12 05:23:40 -05:00
return next(error) if error?
return res.send(404) if !user?
UserController.sendFormattedPersonalInfo(user, res, next)
sendFormattedPersonalInfo: (user, res, next = (error) ->) ->
2017-01-06 07:41:58 -05:00
info = UserController.formatPersonalInfo(user)
res.send JSON.stringify(info)
2014-02-12 05:23:40 -05:00
2017-01-06 07:41:58 -05:00
formatPersonalInfo: (user, callback = (error, info) ->) ->
if !user?
return {}
2017-01-06 07:41:58 -05:00
formatted_user = { id: user._id.toString() }
for key in ["first_name", "last_name", "email", "signUpDate", "role", "institution"]
if user[key]?
formatted_user[key] = user[key]
return formatted_user