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

Added verifyToken middleware to aliases route, added check for user existance on POST/auth

This commit is contained in:
timakasucces 2019-03-06 23:03:37 +03:00
parent 90c7a2e363
commit ae18f115f0
2 changed files with 6 additions and 1 deletions

View file

@ -3,13 +3,14 @@ const router = express.Router();
const Aliases = require('../controllers/aliases');
const Pages = require('../controllers/pages');
const Alias = require('../models/alias');
const verifyToken = require('./middlewares/token');
/**
* GET /*
*
* Return document with given alias
*/
router.get('*', async (req, res) => {
router.get('*', verifyToken, async (req, res) => {
try {
const alias = await Aliases.get(req.originalUrl.slice(1)); // Cuts first '/' character

View file

@ -28,6 +28,10 @@ router.get('/auth', csrfProtection, function (req, res) {
router.post('/auth', parseForm, csrfProtection, async (req, res) => {
let userDoc = await Users.get();
if (!userDoc) {
throw new Error('Password not set');
}
const passHash = userDoc.passHash;
bcrypt.compare(req.body.password, passHash, async (err, result) => {