overleaf/services/web/app/coffee/Features/User/UserEmailsController.coffee
2018-06-11 10:35:23 +02:00

43 lines
1.3 KiB
CoffeeScript

AuthenticationController = require('../Authentication/AuthenticationController')
UserGetter = require("./UserGetter")
UserUpdater = require("./UserUpdater")
EmailHelper = require("../Helpers/EmailHelper")
logger = require("logger-sharelatex")
module.exports = UserEmailsController =
list: (req, res) ->
userId = AuthenticationController.getLoggedInUserId(req)
UserGetter.getUserFullEmails userId, (error, fullEmails) ->
return res.sendStatus 500 if error?
res.json fullEmails
add: (req, res) ->
userId = AuthenticationController.getLoggedInUserId(req)
email = EmailHelper.parseEmail(req.body.email)
return res.sendStatus 422 unless email?
UserUpdater.addEmailAddress userId, email, (error)->
return res.sendStatus 500 if error?
res.sendStatus 200
remove: (req, res) ->
userId = AuthenticationController.getLoggedInUserId(req)
email = EmailHelper.parseEmail(req.body.email)
return res.sendStatus 422 unless email?
UserUpdater.removeEmailAddress userId, email, (error)->
return res.sendStatus 500 if error?
res.sendStatus 200
setDefault: (req, res) ->
userId = AuthenticationController.getLoggedInUserId(req)
email = EmailHelper.parseEmail(req.body.email)
return res.sendStatus 422 unless email?
UserUpdater.setDefaultEmailAddress userId, email, (error)->
return res.sendStatus 500 if error?
res.sendStatus 200