mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Allow partial updates to user settings
This commit is contained in:
parent
63f958af07
commit
0ef7e54ad3
2 changed files with 22 additions and 22 deletions
|
@ -2,7 +2,6 @@ UserDeleter = require("./UserDeleter")
|
|||
UserLocator = require("./UserLocator")
|
||||
User = require("../../models/User").User
|
||||
newsLetterManager = require('../Newsletter/NewsletterManager')
|
||||
sanitize = require('sanitizer')
|
||||
UserRegistrationHandler = require("./UserRegistrationHandler")
|
||||
logger = require("logger-sharelatex")
|
||||
metrics = require("../../infrastructure/Metrics")
|
||||
|
@ -28,25 +27,34 @@ module.exports =
|
|||
|
||||
updateUserSettings : (req, res)->
|
||||
logger.log user: req.session.user, "updating account settings"
|
||||
newEmail = req.body.email?.trim()
|
||||
user_id = req.session.user._id
|
||||
User.findById user_id, (err, user)->
|
||||
if err? or !user?
|
||||
logger.err err:err, user_id: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
|
||||
|
||||
if req.body.first_name?
|
||||
user.first_name = req.body.first_name.trim()
|
||||
if req.body.last_name?
|
||||
user.last_name = req.body.last_name.trim()
|
||||
if req.body.mode?
|
||||
user.ace.mode = req.body.mode
|
||||
if req.body.theme?
|
||||
user.ace.theme = req.body.theme
|
||||
if req.body.fontSize?
|
||||
user.ace.fontSize = req.body.fontSize
|
||||
if req.body.autoComplete?
|
||||
user.ace.autoComplete = (req.body.autoComplete == "true")
|
||||
if req.body.spellCheckLanguage?
|
||||
user.ace.spellCheckLanguage = req.body.spellCheckLanguage
|
||||
if req.body.pdfViewer?
|
||||
user.ace.pdfViewer = req.body.pdfViewer
|
||||
user.save (err)->
|
||||
if !newEmail? or newEmail.length == 0 or newEmail.indexOf("@") == -1
|
||||
return res.send(400)
|
||||
else if newEmail == user.email
|
||||
newEmail = req.body.email?.trim()
|
||||
if !newEmail? or newEmail == user.email
|
||||
return res.send 200
|
||||
else if newEmail.indexOf("@") == -1
|
||||
return res.send(400)
|
||||
else
|
||||
UserUpdater.changeEmailAddress user_id, newEmail, (err)->
|
||||
if err?
|
||||
|
|
|
@ -97,20 +97,12 @@ describe "UserController", ->
|
|||
|
||||
it "should set some props on ace", (done)->
|
||||
@req.body =
|
||||
theme: "something "
|
||||
theme: "something"
|
||||
@res.send = (code)=>
|
||||
@user.ace.theme.should.equal "something"
|
||||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
|
||||
it "should return an error if the email address is null", (done)->
|
||||
@req.body.email = null
|
||||
@res.send = (code)->
|
||||
code.should.equal 400
|
||||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
it "should send an error if the email is 0 len", (done)->
|
||||
@req.body.email = ""
|
||||
@res.send = (code)->
|
||||
|
|
Loading…
Reference in a new issue