1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 15:05:26 +02:00

Merge branch 'master' of https://github.com/codex-team/codex.docs into authentication

This commit is contained in:
timakasucces 2019-03-06 21:23:29 +03:00
commit 90c7a2e363
6 changed files with 27 additions and 19 deletions

View file

@ -42,3 +42,9 @@ $ yarn lint
``` ```
$ yarn test $ yarn test
``` ```
### Authentication
To manage pages you need to authorize (available on `/auth`).
To generate password use `yarn generatePassword [password]` command.

View file

@ -55,7 +55,7 @@ function createMenuTree(parentPageId, pages, pagesOrder, level = 1, currentLevel
* @param res * @param res
* @param next * @param next
*/ */
module.exports = asyncMiddleware(async function (req, res, next) { module.exports = asyncMiddleware(async (req, res, next) => {
/** /**
* Pages without parent * Pages without parent
* @type {string} * @type {string}

View file

@ -13,10 +13,13 @@ module.exports = async function verifyToken(req, res, next) {
let token = req.cookies.authToken; let token = req.cookies.authToken;
const userDoc = await Users.get(); const userDoc = await Users.get();
if (userDoc) { if (!userDoc) {
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => { res.locals.isAuthorized = false;
res.locals.isAuthorized = !(err || !decodedToken); next();
next();
});
} }
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => {
res.locals.isAuthorized = !(err || !decodedToken);
next();
});
}; };

View file

@ -26,7 +26,7 @@ router.get('/page/edit/:id', verifyToken, allowEdit, async (req, res, next) => {
try { try {
const page = await Pages.get(pageId); const page = await Pages.get(pageId);
const pagesAvailable = await Pages.getAllExceptChildrens(pageId); const pagesAvailable = await Pages.getAllExceptChildren(pageId);
const parentsChildrenOrdered = await PagesOrder.getOrderedChildren(pagesAvailable, pageId, page._parent, true); const parentsChildrenOrdered = await PagesOrder.getOrderedChildren(pagesAvailable, pageId, page._parent, true);
res.render('pages/form', { res.render('pages/form', {

View file

@ -2,19 +2,19 @@
<a href="/" class="docs-header__logo"> <a href="/" class="docs-header__logo">
{{ config.title }} {{ config.title }}
</a> </a>
<ul class="docs-header__menu-add"> <ul class="docs-header__menu">
<li> {% if isAuthorized == true %}
{% if isAuthorized == true %} <li class="docs-header__menu-add">
<a class="docs-header__button" href="/page/new"> <a class="docs-header__button" href="/page/new">
{{ svg('plus') }} {{ svg('plus') }}
Add Page Add Page
</a> </a>
{% endif %} </li>
</li> {% endif %}
{% for option in config.menu %} {% for option in config.menu %}
<li> <li>
<a <a
{% if child.uri %} {% if option.uri %}
href="{{ option.uri }}" href="{{ option.uri }}"
{% else %} {% else %}
href="/page/{{ option._id }}" href="/page/{{ option._id }}"

View file

@ -6,13 +6,12 @@ const { expect } = chai;
chai.use(chaiHTTP); chai.use(chaiHTTP);
describe('Express app', () => { describe('Express app', () => {
it('App is available', async (done) => { it('App is available', async () => {
let agent = chai.request.agent(app); let agent = chai.request.agent(app);
const result = await agent const result = await agent
.get('/'); .get('/');
expect(result).to.have.status(200); expect(result).to.have.status(200);
done();
}); });
}); });