moved user settings page to the user pages controller

This commit is contained in:
Henry Oswald 2014-04-09 15:04:47 +01:00
parent 823f4a5eb9
commit 12773c26c2
5 changed files with 59 additions and 34 deletions

View file

@ -1,4 +1,8 @@
UserLocator = require("./UserLocator")
dropboxHandler = require('../Dropbox/DropboxHandler')
logger = require("logger-sharelatex")
Settings = require("settings-sharelatex")
fs = require('fs')
module.exports =
@ -27,3 +31,28 @@ module.exports =
res.render 'user/passwordReset',
title: 'Password Reset'
settingsPage : (req, res)->
logger.log user: req.session.user, "loading settings page"
UserLocator.findById req.session.user._id, (err, user)->
dropboxHandler.getUserRegistrationStatus user._id, (err, status)->
userIsRegisteredWithDropbox = !err? and status.registered
res.render 'user/settings',
title:'Your settings',
userHasDropboxFeature: user.features.dropbox
userIsRegisteredWithDropbox: userIsRegisteredWithDropbox
user: user,
themes: THEME_LIST,
editors: ['default','vim','emacs'],
fontSizes: ['10','11','12','13','14','16','20','24']
languages: Settings.languages,
accountSettingsTabActive: true
THEME_LIST = []
do generateThemeList = () ->
files = fs.readdirSync __dirname + '/../../../../public/js/ace/theme'
for file in files
if file.slice(-2) == "js"
cleanName = file.slice(0,-3)
THEME_LIST.push name: cleanName

View file

@ -105,22 +105,6 @@ module.exports =
logger.err err: err, 'error destorying session'
res.redirect '/login'
settings : (req, res)->
logger.log user: req.session.user, "loading settings page"
User.findById req.session.user._id, (err, user)->
dropboxHandler.getUserRegistrationStatus user._id, (err, status)->
userIsRegisteredWithDropbox = !err? and status.registered
res.render 'user/settings',
title:'Your settings',
userCanSeeDropbox: user.featureSwitches.dropbox
userHasDropboxFeature: user.features.dropbox
userIsRegisteredWithDropbox: userIsRegisteredWithDropbox
user: user,
themes: THEME_LIST,
editors: ['default','vim','emacs'],
fontSizes: ['10','11','12','13','14','16','20','24']
languages: Settings.languages,
accountSettingsTabActive: true
unsubscribe: (req, res)->
User.findById req.session.user._id, (err, user)->
@ -183,10 +167,4 @@ module.exports =
res.send(200)
THEME_LIST = []
do generateThemeList = () ->
files = fs.readdirSync __dirname + '/../../../public/js/ace/theme'
for file in files
if file.slice(-2) == "js"
cleanName = file.slice(0,-3)
THEME_LIST.push name: cleanName

View file

@ -75,7 +75,7 @@ module.exports = class Router
if Settings.enableSubscriptions
app.get '/user/bonus', AuthenticationController.requireLogin(), ReferalMiddleware.getUserReferalId, ReferalController.bonus
app.get '/user/settings', AuthenticationController.requireLogin(), UserController.settings
app.get '/user/settings', AuthenticationController.requireLogin(), UserPagesController.settingsPage
app.post '/user/settings', AuthenticationController.requireLogin(), UserController.apiUpdate
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
app.get '/user/passwordreset', UserPagesController.passwordResetPage

View file

@ -11,10 +11,10 @@ ObjectId = require("mongojs").ObjectId
describe "UserController", ->
beforeEach ->
@UserDeleter =
deleteUser: sinon.stub().callsArgWith(1)
@UserController = SandboxedModule.require modulePath, requires:
"./UserDeleter": @UserDeleter
"logger-sharelatex": {log:->}
@req = new MockRequest()
@res = new MockResponse()
@ -33,7 +33,3 @@ describe "UserController", ->
@UserController.deleteUser @req, @res

View file

@ -11,14 +11,25 @@ describe "UserPagesController", ->
beforeEach ->
@settings = {}
@user =
_id:"kwjewkl"
features:{}
@UserDeleter =
deleteUser: sinon.stub().callsArgWith(1)
@UserLocator =
findById: sinon.stub().callsArgWith(1, null, @user)
@dropboxStatus = {}
@DropboxHandler =
getUserRegistrationStatus : sinon.stub().callsArgWith(1, null, @dropboxStatus)
@UserPagesController = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"./UserLocator": @UserLocator
'../Dropbox/DropboxHandler': @DropboxHandler
@req =
query:{}
session:{}
session:
user:@user
@res = {}
@ -89,5 +100,16 @@ describe "UserPagesController", ->
@UserPagesController.passwordResetPage @req, @res
describe "settingsPage", ->
it "should render user/settings", (done)->
@res.render = (page)->
page.should.equal "user/settings"
done()
@UserPagesController.settingsPage @req, @res
it "should send user", (done)->
@res.render = (page, opts)=>
opts.user.should.equal @user
done()
@UserPagesController.settingsPage @req, @res