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

src/server/routes/users/get/reset.js   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 41
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
wmc 5
nc 1
mnd 2
bc 5
fnc 2
dl 0
loc 41
rs 10
bpm 2.5
cpm 2.5
noi 2
c 2
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B reset.js ➔ route 0 29 3
1
import fs from 'fs-extra'
2
import path from 'path'
3
4
import {
5
  coreUtils,
6
  config,
7
  Handlebars,
8
  User
9
} from '../../../../cli'
10
11
var route = function route(req, res) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable route already seems to be declared on line 11. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
12
  var resHtml = ''
13
  if(typeof req.query.token !== 'undefined' && req.query.token !== null) {
14
    User.utils.findByResetPasswordToken(req.query.token, function () {
15
16
      var page = path.join(__dirname + '/../../../views/users/reset.html')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
17
      if (coreUtils.file.exist(page)) {
18
        resHtml = fs.readFileSync(page, 'utf8')
19
      }
20
      
21
      var template = Handlebars.compile(resHtml, {noEscape: true})
22
23
      var tmp = template({
24
        csrfToken: res.locals.csrfToken,
25
        config: JSON.stringify(config),
26
        express: {
27
          req: req,
28
          res: res
29
        },
30
        token: req.query.token,
31
        info: req.flash('info')
32
      })
33
34
      return res.send(tmp)
35
    })
36
  }else {
37
    res.redirect('/abe/users/forgot')
38
  }
39
}
40
41
export default route