mirror of https://github.com/Requarks/wiki.git
NGPixel
8 years ago
9 changed files with 122 additions and 17 deletions
Split View
Diff Options
-
12README.md
-
6assets/js/libs.js
-
8libs/auth.js
-
57libs/rights.js
-
6middlewares/auth.js
-
5models/user.js
-
10package.json
-
4server.js
-
31views/error-forbidden.pug
6
assets/js/libs.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,57 @@ |
|||
"use strict"; |
|||
|
|||
const _ = require('lodash'); |
|||
|
|||
/** |
|||
* Rights |
|||
*/ |
|||
module.exports = { |
|||
|
|||
|
|||
check(req, role) { |
|||
|
|||
let rt = []; |
|||
let p = _.chain(req.originalUrl).toLower().trim().value(); |
|||
|
|||
// Load User Rights
|
|||
|
|||
if(_.isArray(req.user.rights)) { |
|||
rt = req.user.rights; |
|||
} |
|||
|
|||
// Is admin?
|
|||
|
|||
if(_.find(rt, { role: 'admin' })) { |
|||
return true; |
|||
} |
|||
|
|||
// Check specific role on path
|
|||
|
|||
let filteredRights = _.filter(rt, (r) => { |
|||
if(r.role === role || (r.role === 'write' && role === 'read')) { |
|||
if((!r.exact && _.startsWith(p, r.path)) || (r.exact && p === r.path)) { |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
}); |
|||
|
|||
// Check for deny scenario
|
|||
|
|||
let isValid = false; |
|||
|
|||
if(filteredRights.length > 1) { |
|||
isValid = !_.chain(filteredRights).sortBy((r) => { |
|||
return r.path.length + ((r.deny) ? 0.5 : 0); |
|||
}).last().get('deny').value(); |
|||
} else if(filteredRights.length == 1 && filteredRights[0].deny === false) { |
|||
isValid = true; |
|||
} |
|||
|
|||
// Deny by default
|
|||
|
|||
return isValid; |
|||
|
|||
} |
|||
|
|||
}; |
@ -0,0 +1,31 @@ |
|||
doctype html |
|||
html |
|||
head |
|||
meta(http-equiv='X-UA-Compatible', content='IE=edge') |
|||
meta(charset='UTF-8') |
|||
meta(name='viewport', content='width=device-width, initial-scale=1') |
|||
meta(name='theme-color', content='#009688') |
|||
meta(name='msapplication-TileColor', content='#009688') |
|||
meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png') |
|||
title= appconfig.title |
|||
|
|||
// Favicon |
|||
each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180] |
|||
link(rel='apple-touch-icon', sizes=favsize + 'x' + favsize, href='/favicons/apple-icon-' + favsize + 'x' + favsize + '.png') |
|||
link(rel='icon', type='image/png', sizes='192x192', href='/favicons/android-icon-192x192.png') |
|||
each favsize in [32, 96, 16] |
|||
link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png') |
|||
link(rel='manifest', href='/manifest.json') |
|||
|
|||
// CSS |
|||
link(type='text/css', rel='stylesheet', href='/css/libs.css') |
|||
link(type='text/css', rel='stylesheet', href='/css/app.css') |
|||
|
|||
body(class='server-error') |
|||
section.hero.is-danger.is-fullheight |
|||
.hero-body |
|||
.container |
|||
a(href='/'): img(src='/favicons/android-icon-96x96.png') |
|||
h1.title(style={ 'margin-top': '30px'}) Forbidden |
|||
h2.subtitle(style={ 'margin-bottom': '50px'}) Sorry, you don't have the necessary permissions to access this page. |
|||
a.button.is-dark.is-inverted(href='/') Go Home |
Write
Preview
Loading…
Cancel
Save