mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 06:55:26 +02:00
Merge branch 'master' of https://github.com/codex-team/codex.docs into authentication
This commit is contained in:
commit
90c7a2e363
6 changed files with 27 additions and 19 deletions
|
@ -42,3 +42,9 @@ $ yarn lint
|
|||
```
|
||||
$ yarn test
|
||||
```
|
||||
|
||||
### Authentication
|
||||
|
||||
To manage pages you need to authorize (available on `/auth`).
|
||||
|
||||
To generate password use `yarn generatePassword [password]` command.
|
||||
|
|
|
@ -55,7 +55,7 @@ function createMenuTree(parentPageId, pages, pagesOrder, level = 1, currentLevel
|
|||
* @param res
|
||||
* @param next
|
||||
*/
|
||||
module.exports = asyncMiddleware(async function (req, res, next) {
|
||||
module.exports = asyncMiddleware(async (req, res, next) => {
|
||||
/**
|
||||
* Pages without parent
|
||||
* @type {string}
|
||||
|
|
|
@ -13,10 +13,13 @@ module.exports = async function verifyToken(req, res, next) {
|
|||
let token = req.cookies.authToken;
|
||||
const userDoc = await Users.get();
|
||||
|
||||
if (userDoc) {
|
||||
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => {
|
||||
res.locals.isAuthorized = !(err || !decodedToken);
|
||||
next();
|
||||
});
|
||||
if (!userDoc) {
|
||||
res.locals.isAuthorized = false;
|
||||
next();
|
||||
}
|
||||
|
||||
jwt.verify(token, userDoc.passHash + config.secret, (err, decodedToken) => {
|
||||
res.locals.isAuthorized = !(err || !decodedToken);
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ router.get('/page/edit/:id', verifyToken, allowEdit, async (req, res, next) => {
|
|||
|
||||
try {
|
||||
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);
|
||||
|
||||
res.render('pages/form', {
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
<a href="/" class="docs-header__logo">
|
||||
{{ config.title }}
|
||||
</a>
|
||||
<ul class="docs-header__menu-add">
|
||||
<li>
|
||||
{% if isAuthorized == true %}
|
||||
<a class="docs-header__button" href="/page/new">
|
||||
{{ svg('plus') }}
|
||||
Add Page
|
||||
</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
<ul class="docs-header__menu">
|
||||
{% if isAuthorized == true %}
|
||||
<li class="docs-header__menu-add">
|
||||
<a class="docs-header__button" href="/page/new">
|
||||
{{ svg('plus') }}
|
||||
Add Page
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for option in config.menu %}
|
||||
<li>
|
||||
<a
|
||||
{% if child.uri %}
|
||||
{% if option.uri %}
|
||||
href="{{ option.uri }}"
|
||||
{% else %}
|
||||
href="/page/{{ option._id }}"
|
||||
|
|
|
@ -6,13 +6,12 @@ const { expect } = chai;
|
|||
chai.use(chaiHTTP);
|
||||
|
||||
describe('Express app', () => {
|
||||
it('App is available', async (done) => {
|
||||
it('App is available', async () => {
|
||||
let agent = chai.request.agent(app);
|
||||
|
||||
const result = await agent
|
||||
.get('/');
|
||||
|
||||
expect(result).to.have.status(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue