|
|
@ -6,7 +6,9 @@ const multer = require('multer');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const moment = require('moment');
|
|
|
|
const moment = require('moment');
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
|
|
|
const bCrypt = require('bcrypt-nodejs');
|
|
|
|
const book = new Book();
|
|
|
|
const book = new Book();
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
const uploadPath =
|
|
|
|
const uploadPath =
|
|
|
|
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
|
|
|
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
|
|
|
fs.ensureDir(uploadPath, () => {
|
|
|
|
fs.ensureDir(uploadPath, () => {
|
|
|
@ -42,8 +44,17 @@ router.get('/', (req, res) => {
|
|
|
|
Update Page
|
|
|
|
Update Page
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
/**
|
|
|
|
|
|
|
|
if (req.session.user) {
|
|
|
|
if (req.session.user) {
|
|
|
|
|
|
|
|
//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;
|
|
|
|
var member = req.session.user;
|
|
|
|
jwt.verify(req.session.token, member.key, function(err, decoded) {
|
|
|
|
jwt.verify(req.session.token, member.key, function(err, decoded) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
@ -52,7 +63,8 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|
|
|
console.log('YUP', decoded);
|
|
|
|
console.log('YUP', decoded);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var feature = '';
|
|
|
|
var feature = '';
|
|
|
|
if (req.files.length > 0) {
|
|
|
|
if (req.files.length > 0) {
|
|
|
|
var path = req.files[0].path;
|
|
|
|
var path = req.files[0].path;
|
|
|
@ -141,3 +153,7 @@ router.post('/add-post-image', post_upload, function(req, res) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|
|
|
|
module.exports = router;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isTokenValid(token, hashedToken) {
|
|
|
|
|
|
|
|
return bCrypt.compareSync(token, hashedToken);
|
|
|
|
|
|
|
|
}
|
|
|
|