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

src/server/middlewares/checkCsrf.js   A

Complexity

Total Complexity 7
Complexity/F 7

Size

Lines of Code 23
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
nc 1
mnd 2
bc 6
fnc 1
dl 0
loc 23
rs 10
bpm 6
cpm 7
noi 2
c 1
b 0
f 0
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