|
|
@ -1,16 +1,15 @@
|
|
|
|
import DateUtils from '../../tools/utilities/DateUtils';
|
|
|
|
import DateUtils from '../../utils/tools/DateUtils';
|
|
|
|
import * as DataEvent from '../../tools/events/DataEvent';
|
|
|
|
import * as DataEvent from '../../utils/events/DataEvent';
|
|
|
|
import RightsManager, {
|
|
|
|
import RightsManager, {
|
|
|
|
TASK_CREATE,
|
|
|
|
TASK_CREATE,
|
|
|
|
TASK_UPDATE,
|
|
|
|
TASK_UPDATE,
|
|
|
|
OBJECT_POST,
|
|
|
|
OBJECT_POST,
|
|
|
|
OBJECT_SETTINGS
|
|
|
|
OBJECT_SETTINGS
|
|
|
|
} from '../../tools/utilities/RightsManager';
|
|
|
|
} from '../../utils/tools/RightsManager';
|
|
|
|
const express = require('express');
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const router = express.Router();
|
|
|
|
const multer = require('multer');
|
|
|
|
const multer = require('multer');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const Models = require('../../models');
|
|
|
|
|
|
|
|
const dateUtils = new DateUtils();
|
|
|
|
const dateUtils = new DateUtils();
|
|
|
|
const rightsManager = new RightsManager();
|
|
|
|
const rightsManager = new RightsManager();
|
|
|
|
const uploadPath =
|
|
|
|
const uploadPath =
|
|
|
@ -40,56 +39,54 @@ var background_upload = multer({
|
|
|
|
//** SYNC POSTS */
|
|
|
|
//** SYNC POSTS */
|
|
|
|
router.post('/sync', (req, res) => {
|
|
|
|
router.post('/sync', (req, res) => {
|
|
|
|
let payload = req.body;
|
|
|
|
let payload = req.body;
|
|
|
|
Models.User.findById(req.session.user.id).then(user => {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
|
|
|
fs.readJson('config/site-settings.json')
|
|
|
|
fs.readJson('config/site-settings.json')
|
|
|
|
.then(obj => {
|
|
|
|
.then(obj => {
|
|
|
|
if (user.hande != payload.handle || user.email != payload.email) {
|
|
|
|
if (user.hande != payload.handle || user.email != payload.email) {
|
|
|
|
user.update({
|
|
|
|
user.update({
|
|
|
|
handle: payload.handle,
|
|
|
|
handle: payload.handle,
|
|
|
|
email: payload.email
|
|
|
|
email: payload.email
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
|
|
//console.log('UPDATED');
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
//console.log('ERR', err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//console.log('USER NOT UPDATED');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.url = payload.url;
|
|
|
|
|
|
|
|
obj.title = payload.title;
|
|
|
|
|
|
|
|
obj.description = payload.descriptions;
|
|
|
|
|
|
|
|
obj.private = payload.private;
|
|
|
|
|
|
|
|
obj.theme = payload.theme;
|
|
|
|
|
|
|
|
obj.background = payload.background; //TODO: make this url relative
|
|
|
|
|
|
|
|
//mail stuff
|
|
|
|
|
|
|
|
obj.email.active = payload.mailSettings.activeProtocol;
|
|
|
|
|
|
|
|
obj.email.smtp.domain = payload.mailSettings.smtp.domain;
|
|
|
|
|
|
|
|
obj.email.smtp.email = payload.mailSettings.smtp.email;
|
|
|
|
|
|
|
|
obj.email.smtp.password = payload.mailSettings.smtp.password;
|
|
|
|
|
|
|
|
obj.email.mailgun.domain = payload.mailSettings.mailgun.domain;
|
|
|
|
|
|
|
|
obj.email.mailgun['api-key'] = payload.mailSettings.mailgun.key;
|
|
|
|
|
|
|
|
fs.writeJson('config/site-settings.json', obj)
|
|
|
|
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
res.json({
|
|
|
|
//console.log('UPDATED');
|
|
|
|
message: DataEvent.SETTINGS_UPDATED
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
.catch(() => {
|
|
|
|
//console.error(err);
|
|
|
|
//console.log('ERR', err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
.catch(() => {
|
|
|
|
//console.log('USER NOT UPDATED');
|
|
|
|
//console.error(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
obj.url = payload.url;
|
|
|
|
} else {
|
|
|
|
obj.title = payload.title;
|
|
|
|
res.json({
|
|
|
|
obj.description = payload.descriptions;
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
obj.private = payload.private;
|
|
|
|
|
|
|
|
obj.theme = payload.theme;
|
|
|
|
|
|
|
|
obj.background = payload.background; //TODO: make this url relative
|
|
|
|
|
|
|
|
//mail stuff
|
|
|
|
|
|
|
|
obj.email.active = payload.mailSettings.activeProtocol;
|
|
|
|
|
|
|
|
obj.email.smtp.domain = payload.mailSettings.smtp.domain;
|
|
|
|
|
|
|
|
obj.email.smtp.email = payload.mailSettings.smtp.email;
|
|
|
|
|
|
|
|
obj.email.smtp.password = payload.mailSettings.smtp.password;
|
|
|
|
|
|
|
|
obj.email.mailgun.domain = payload.mailSettings.mailgun.domain;
|
|
|
|
|
|
|
|
obj.email.mailgun['api-key'] = payload.mailSettings.mailgun.key;
|
|
|
|
|
|
|
|
fs.writeJson('config/site-settings.json', obj)
|
|
|
|
|
|
|
|
.then(() => {
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
message: DataEvent.SETTINGS_UPDATED
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
//console.error(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
//console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.get('/nav', function(req, res) {
|
|
|
|
router.get('/nav', function(req, res) {
|
|
|
@ -110,30 +107,28 @@ router.get('/nav', function(req, res) {
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/nav-sync', (req, res) => {
|
|
|
|
router.post('/nav-sync', (req, res) => {
|
|
|
|
let payload = req.body;
|
|
|
|
let payload = req.body;
|
|
|
|
Models.User.findById(req.session.user.id).then(user => {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
|
|
|
fs.readJson('config/site-settings.json')
|
|
|
|
fs.readJson('config/site-settings.json')
|
|
|
|
.then(obj => {
|
|
|
|
.then(obj => {
|
|
|
|
obj.menu = payload;
|
|
|
|
obj.menu = payload;
|
|
|
|
fs.writeJson('config/site-settings.json', obj)
|
|
|
|
fs.writeJson('config/site-settings.json', obj)
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
res.json({
|
|
|
|
res.json({
|
|
|
|
message: DataEvent.SETTINGS_UPDATED
|
|
|
|
message: DataEvent.SETTINGS_UPDATED
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
//console.error(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
.catch(() => {
|
|
|
|
//console.error(err);
|
|
|
|
//console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
})
|
|
|
|
res.json({
|
|
|
|
.catch(() => {
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
//console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
/***
|
|
|
@ -145,37 +140,35 @@ router.post('/add-avatar', function(req, res) {
|
|
|
|
return res.json({
|
|
|
|
return res.json({
|
|
|
|
message: 'You need to be logged in, champ.'
|
|
|
|
message: 'You need to be logged in, champ.'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Models.User.findById(req.session.user.id).then(user => {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
|
|
|
|
avatar_upload(req, res, function(err) {
|
|
|
|
avatar_upload(req, res, function(err) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
res.json({
|
|
|
|
res.json({
|
|
|
|
message: err
|
|
|
|
message: err
|
|
|
|
});
|
|
|
|
});
|
|
|
|
throw err;
|
|
|
|
throw err;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var avatar = req.files[0].path;
|
|
|
|
var avatar = req.files[0].path;
|
|
|
|
user.update({
|
|
|
|
user.update({
|
|
|
|
avatar: avatar.substr(7, avatar.length)
|
|
|
|
avatar: avatar.substr(7, avatar.length)
|
|
|
|
})
|
|
|
|
|
|
|
|
.then(updated => {
|
|
|
|
|
|
|
|
req.session.user = updated;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(updated => {
|
|
|
|
.catch(() => {
|
|
|
|
req.session.user = updated;
|
|
|
|
//console.log('ERR', err);
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
|
|
//console.log('ERR', err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return res.json({
|
|
|
|
|
|
|
|
message: DataEvent.AVATAR_UPLOADED,
|
|
|
|
|
|
|
|
url: avatar.substr(7, avatar.length)
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return res.json({
|
|
|
|
});
|
|
|
|
message: DataEvent.AVATAR_UPLOADED,
|
|
|
|
} else {
|
|
|
|
url: avatar.substr(7, avatar.length)
|
|
|
|
res.json({
|
|
|
|
});
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
res.json({
|
|
|
|
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
/***
|
|
|
|
/***
|
|
|
|
UPLOAD FEATURE BACKGROUND
|
|
|
|
UPLOAD FEATURE BACKGROUND
|
|
|
@ -186,27 +179,25 @@ router.post('/add-feature-background', function(req, res) {
|
|
|
|
return res.json({
|
|
|
|
return res.json({
|
|
|
|
message: 'You need to be logged in, champ.'
|
|
|
|
message: 'You need to be logged in, champ.'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Models.User.findById(req.session.user.id).then(user => {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
|
|
|
|
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
|
|
|
|
background_upload(req, res, function(err) {
|
|
|
|
background_upload(req, res, function(err) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
res.json({
|
|
|
|
res.json({
|
|
|
|
message: err
|
|
|
|
message: err
|
|
|
|
});
|
|
|
|
});
|
|
|
|
throw err;
|
|
|
|
throw err;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var bgImage = req.files[0].path;
|
|
|
|
var bgImage = req.files[0].path;
|
|
|
|
return res.json({
|
|
|
|
return res.json({
|
|
|
|
message: DataEvent.SITE_BACKGROUND_UPLOADED,
|
|
|
|
message: DataEvent.SITE_BACKGROUND_UPLOADED,
|
|
|
|
url: bgImage.substr(7, bgImage.length)
|
|
|
|
url: bgImage.substr(7, bgImage.length)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.json({
|
|
|
|
res.json({
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
module.exports = router;
|
|
|
|
module.exports = router;
|
|
|
|