-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nicolaslabbe
committed
Nov 22, 2016
1 parent
e416161
commit 20c0d7d
Showing
38 changed files
with
1,599 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Cookies from 'cookies' | ||
import jwt from 'jwt-simple' | ||
|
||
import { | ||
config, | ||
User | ||
} from '../../../' | ||
|
||
/** | ||
* Handlebars helper, to print className and escape it string | ||
*/ | ||
export default function role(role, obj, ctx) { | ||
if(typeof obj.express !== 'undefined' && obj.express !== null) { | ||
var cookies = new Cookies(obj.express.req, obj.express.res, { | ||
secure: config.cookie.secure | ||
}) | ||
var token = cookies.get('x-access-token'); | ||
|
||
if(typeof token !== 'undefined' && token !== null && token !== '') { | ||
var secret = config.users.secret | ||
var decoded = jwt.decode(token, secret); | ||
|
||
var user = User.findSync(decoded.iss) | ||
|
||
var roles = config.users.roles | ||
var cpt = 0; | ||
var cptUser = 0; | ||
var cptRole = 0; | ||
Array.prototype.forEach.call(roles, (currentRole) => { | ||
if(currentRole.workflow === user.role.workflow) { | ||
cptUser = cpt | ||
} | ||
if(currentRole.workflow === role) { | ||
cptRole = cpt | ||
} | ||
cpt++; | ||
}) | ||
|
||
if(cptRole > cptUser) { | ||
return ''; | ||
} | ||
} | ||
|
||
var content = ctx.fn(this) | ||
return content | ||
|
||
}else { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.