Completed
Pull Request — master (#40)
by
unknown
01:39
created

src/cli/cms/templates/handlebars/getCurrentuserRole.js   A

Complexity

Total Complexity 6
Complexity/F 6

Size

Lines of Code 26
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B getCurrentuserRole.js ➔ getCurrentuserRole 0 15 6
1
import Cookies from 'cookies'
2
import jwt from 'jwt-simple'
3
4
import {
5
  config,
6
	User
7
} from '../../../'
8
9
/**
10
 * Handlebars helper, to print className and escape it string
11
 */
12
export default function getCurrentuserRole(obj) {
13
  if(typeof obj.express !== 'undefined' && obj.express !== null) {
14
    var cookies = new Cookies(obj.express.req, obj.express.res, {
15
      secure: config.cookie.secure
16
    })
17
    var token = cookies.get('x-access-token')
18
    if(typeof token !== 'undefined' && token !== null && token !== '') {
19
      var secret = config.users.secret
20
      var decoded = jwt.decode(token, secret)
21
      var user = User.utils.findSync(decoded.iss)
22
      return user.role.workflow
23
    }
24
  }
25
  return ''
26
}
27