|
|
|
@ -6,7 +6,9 @@ const multer = require('multer');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
const bCrypt = require('bcrypt-nodejs');
|
|
|
|
|
const book = new Book();
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const uploadPath =
|
|
|
|
|
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
|
|
|
|
fs.ensureDir(uploadPath, () => {
|
|
|
|
@ -42,17 +44,27 @@ router.get('/', (req, res) => {
|
|
|
|
|
Update Page
|
|
|
|
|
*/
|
|
|
|
|
router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
|
/**
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
var member = req.session.user;
|
|
|
|
|
jwt.verify(req.session.token, member.key, function(err, decoded) {
|
|
|
|
|
if (err) {
|
|
|
|
|
console('NOPE', err);
|
|
|
|
|
}
|
|
|
|
|
console.log('YUP', decoded);
|
|
|
|
|
});
|
|
|
|
|
//Get enctrypted hashed token from header request
|
|
|
|
|
let hash = req.headers['x-access-token'];
|
|
|
|
|
//Checks if token is a proper hash, if not reject
|
|
|
|
|
if (!isTokenValid(req.session.token, hash)) {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.API_REQUEST_LAME,
|
|
|
|
|
message: 'Invalid Token. Auth Blocked'
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
//console.log('TOKEN IS GOOD');
|
|
|
|
|
var member = req.session.user;
|
|
|
|
|
jwt.verify(req.session.token, member.key, function(err, decoded) {
|
|
|
|
|
if (err) {
|
|
|
|
|
console('NOPE', err);
|
|
|
|
|
}
|
|
|
|
|
console.log('YUP', decoded);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var feature = '';
|
|
|
|
|
if (req.files.length > 0) {
|
|
|
|
|
var path = req.files[0].path;
|
|
|
|
@ -141,3 +153,7 @@ router.post('/add-post-image', post_upload, function(req, res) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|
|
|
|
|
|
|
|
|
|
function isTokenValid(token, hashedToken) {
|
|
|
|
|
return bCrypt.compareSync(token, hashedToken);
|
|
|
|
|
}
|
|
|
|
|