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

44 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2018-06-08 17:05:19 +00:00
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