2014-04-09 09:50:12 -04:00
|
|
|
UserDeleter = require("./UserDeleter")
|
2014-04-09 11:59:28 -04:00
|
|
|
UserLocator = require("./UserLocator")
|
2014-04-09 11:33:54 -04:00
|
|
|
User = require("../../models/User").User
|
2014-04-09 10:41:19 -04:00
|
|
|
newsLetterManager = require('../Newsletter/NewsletterManager')
|
2014-04-09 11:33:54 -04:00
|
|
|
sanitize = require('sanitizer')
|
|
|
|
logger = require("logger-sharelatex")
|
2014-04-09 11:59:28 -04:00
|
|
|
metrics = require("../../infrastructure/Metrics")
|
2014-04-09 09:50:12 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
deleteUser: (req, res)->
|
|
|
|
user_id = req.session.user._id
|
|
|
|
UserDeleter.deleteUser user_id, (err)->
|
|
|
|
if !err?
|
|
|
|
req.session.destroy()
|
2014-04-09 10:41:19 -04:00
|
|
|
res.send(200)
|
|
|
|
|
|
|
|
unsubscribe: (req, res)->
|
|
|
|
UserLocator.findById req.session.user._id, (err, user)->
|
|
|
|
newsLetterManager.unsubscribe user, ->
|
2014-04-09 11:33:54 -04:00
|
|
|
res.send()
|
|
|
|
|
|
|
|
updateUserSettings : (req, res)->
|
|
|
|
logger.log user: req.session.user, "updating account settings"
|
|
|
|
User.findById req.session.user._id, (err, user)->
|
|
|
|
if err? or !user?
|
|
|
|
logger.err err:err, user_id:req.session.user._id, "problem updaing user settings"
|
|
|
|
return res.send 500
|
|
|
|
user.first_name = sanitize.escape(req.body.first_name).trim()
|
|
|
|
user.last_name = sanitize.escape(req.body.last_name).trim()
|
|
|
|
user.ace.mode = sanitize.escape(req.body.mode).trim()
|
|
|
|
user.ace.theme = sanitize.escape(req.body.theme).trim()
|
|
|
|
user.ace.fontSize = sanitize.escape(req.body.fontSize).trim()
|
|
|
|
user.ace.autoComplete = req.body.autoComplete == "true"
|
|
|
|
user.ace.spellCheckLanguage = req.body.spellCheckLanguage
|
|
|
|
user.ace.pdfViewer = req.body.pdfViewer
|
|
|
|
user.save ->
|
2014-04-09 11:59:28 -04:00
|
|
|
res.send()
|
|
|
|
|
|
|
|
logout : (req, res)->
|
|
|
|
metrics.inc "user.logout"
|
|
|
|
logger.log user: req?.session?.user, "logging out"
|
|
|
|
req.session.destroy (err)->
|
|
|
|
if err
|
|
|
|
logger.err err: err, 'error destorying session'
|
|
|
|
res.redirect '/login'
|
|
|
|
|
|
|
|
|