Completed
Push — master ( 78d2f9...949122 )
by greg
42s
created

checkCsrf.js ➔ middleware   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
nc 4
dl 0
loc 21
rs 7.551
c 1
b 0
f 0
nop 4
1
var middleware = function(err, req, res, next) {
2
  if (err.code !== 'EBADCSRFTOKEN') {
3
    return next(err)
4
  }else {
5
    if( req.url.indexOf('/abe/users/forgot') > -1 || req.url.indexOf('/abe/users/login') > -1 || !/^\/abe/.test(req.url)) {
6
      return next()
7
    }
8
  }
9
10
  var isHtml = /text\/html/.test(req.get('accept')) ? true : false
11
  if(isHtml) {
12
    res.redirect('/abe/users/login')
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
13
  }else {
14
    var notAuthorized = {
15
      success: 0,
16
      message: 'form tampered with !'
17
    }
18
    res.set('Content-Type', 'application/json')
19
    res.send(JSON.stringify(notAuthorized))
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
20
  }
21
}
22
23
export default middleware