Merge branch 'master' into sk-references-2

This commit is contained in:
Shane Kilkelly 2016-01-28 10:06:41 +00:00
commit 50a451970b
4 changed files with 21 additions and 3 deletions

View file

@ -19,6 +19,10 @@ argv = require("optimist")
.argv .argv
Server.app.use (error, req, res, next) -> Server.app.use (error, req, res, next) ->
if error?.code is 'EBADCSRFTOKEN'
logger.log err: error,url:req.url, method:req.method, user:req?.sesson?.user, "invalid csrf"
res.sendStatus(403)
return
logger.error err: error, url:req.url, method:req.method, user:req?.sesson?.user, "error passed to top level next middlewear" logger.error err: error, url:req.url, method:req.method, user:req?.sesson?.user, "error passed to top level next middlewear"
res.statusCode = error.status or 500 res.statusCode = error.status or 500
if res.statusCode == 500 if res.statusCode == 500

View file

@ -35,11 +35,11 @@ module.exports = AuthenticationController =
return next(error) if error? return next(error) if error?
req.session.justLoggedIn = true req.session.justLoggedIn = true
logger.log email: email, user_id: user._id.toString(), "successful log in" logger.log email: email, user_id: user._id.toString(), "successful log in"
res.send redir: redir res.json redir: redir
else else
AuthenticationController._recordFailedLogin() AuthenticationController._recordFailedLogin()
logger.log email: email, "failed log in" logger.log email: email, "failed log in"
res.send message: res.json message:
text: req.i18n.translate("email_or_password_wrong_try_again"), text: req.i18n.translate("email_or_password_wrong_try_again"),
type: 'error' type: 'error'

View file

@ -27,7 +27,7 @@
"http-proxy": "^1.8.1", "http-proxy": "^1.8.1",
"jade": "~1.3.1", "jade": "~1.3.1",
"ldapjs": "^0.7.1", "ldapjs": "^0.7.1",
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.3.0", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.3.1",
"lynx": "0.1.1", "lynx": "0.1.1",
"marked": "^0.3.3", "marked": "^0.3.3",
"method-override": "^2.3.3", "method-override": "^2.3.3",

View file

@ -49,6 +49,20 @@ class MockResponse
@body = body if body @body = body if body
@callback() if @callback? @callback() if @callback?
json: (status, body) ->
if arguments.length < 2
if typeof status != "number"
body = status
status = 200
@statusCode = status
@returned = true
if 200 <= status < 300
@success = true
else
@success = false
@body = body if body
@callback() if @callback?
setHeader: (header, value) -> setHeader: (header, value) ->
@headers[header] = value @headers[header] = value