moved logout to new user controller

This commit is contained in:
Henry Oswald 2014-04-09 16:59:28 +01:00
parent b46576e91f
commit b6b30c3d37
4 changed files with 32 additions and 15 deletions

View file

@ -1,9 +1,10 @@
UserDeleter = require("./UserDeleter")
UserLocator = require("./UserLocator")
User = require("../../models/User").User
newsLetterManager = require('../Newsletter/NewsletterManager')
sanitize = require('sanitizer')
logger = require("logger-sharelatex")
metrics = require("../../infrastructure/Metrics")
module.exports =
@ -34,4 +35,14 @@ module.exports =
user.ace.spellCheckLanguage = req.body.spellCheckLanguage
user.ace.pdfViewer = req.body.pdfViewer
user.save ->
res.send()
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'

View file

@ -95,15 +95,6 @@ module.exports =
type:'failure'
logger.info email: email, "no user found with email"
logout : (req, res)->
metrics.inc "user.logout"
if req.session? && req.session.user?
logger.log user: req.session.user, "logging out"
req.session.destroy (err)->
if err
logger.err err: err, 'error destorying session'
res.redirect '/login'
changePassword : (req, res, next = (error) ->)->
metrics.inc "user.password-change"

View file

@ -51,7 +51,7 @@ module.exports = class Router
app.get '/login', UserPagesController.loginPage
app.post '/login', AuthenticationController.login
app.get '/logout', UserController.logout
app.get '/logout', UserController_new.logout
app.get '/restricted', SecurityManager.restricted
app.get '/resources', HomeController.externalPage("resources", "LaTeX Resources")

View file

@ -18,11 +18,14 @@ describe "UserController", ->
@UserDeleter =
deleteUser: sinon.stub().callsArgWith(1)
@UserLocator =
findById: sinon.stub().callsArgWith(1, null, @user)
@User =
findById: sinon.stub().callsArgWith(1, null, @user)
@NewsLetterManager =
unsubscribe: sinon.stub().callsArgWith(1)
@UserController = SandboxedModule.require modulePath, requires:
"./UserLocator": @UserLocator
"./UserDeleter": @UserDeleter
"../../models/User": User:@User
'../Newsletter/NewsletterManager':@NewsLetterManager
@ -53,8 +56,6 @@ describe "UserController", ->
done()
@UserController.unsubscribe @req, @res
describe "updateUserSettings", ->
it "should call save", (done)->
@ -64,7 +65,6 @@ describe "UserController", ->
done()
@UserController.updateUserSettings @req, @res
it "should set the first name", (done)->
@req.body =
first_name: "bobby "
@ -82,3 +82,18 @@ describe "UserController", ->
@UserController.updateUserSettings @req, @res
describe "logout", ->
it "should destroy the session", (done)->
@req.session.destroy = (cb)->
if cb?
cb()
@res.redirect = (url)=>
url.should.equal "/login"
@req.session.destroy.called.should.equal true
done()
@UserController.logout @req, @res