|
|
|
@ -1,17 +1,10 @@
|
|
|
|
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
|
|
|
|
import RightsManager, {
|
|
|
|
|
TASK_CREATE,
|
|
|
|
|
TASK_UPDATE,
|
|
|
|
|
OBJECT_POST,
|
|
|
|
|
OBJECT_SETTINGS
|
|
|
|
|
} from '../../../src/com/utils/RightsManager';
|
|
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
const multer = require('multer');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const rightsManager = new RightsManager();
|
|
|
|
|
const settings = require('../../../site/settings.json');
|
|
|
|
|
const folks = require('../../../site/folks.json');
|
|
|
|
|
const uploadPath =
|
|
|
|
@ -38,51 +31,59 @@ var background_upload = multer({
|
|
|
|
|
//** SYNC POSTS */
|
|
|
|
|
router.post('/sync', (req, res) => {
|
|
|
|
|
let payload = req.body;
|
|
|
|
|
if (req.handle.user) {
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
let user = req.session.user;
|
|
|
|
|
fs.readJson('site/settings.json')
|
|
|
|
|
.then(obj => {
|
|
|
|
|
if (user.hande != payload.handle || user.email != payload.email) {
|
|
|
|
|
user.update({
|
|
|
|
|
handle: payload.handle,
|
|
|
|
|
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('site/settings.json', obj)
|
|
|
|
|
.then(() => {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.SETTINGS_UPDATED,
|
|
|
|
|
message: 'Settings Saved'
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
//console.error(err);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
//console.error(err);
|
|
|
|
|
let found = _.find(folks, { id: user.id });
|
|
|
|
|
let needToUpdate = false;
|
|
|
|
|
if (found) {
|
|
|
|
|
let index = found.id - 1;
|
|
|
|
|
if (
|
|
|
|
|
folks[index].handle != payload.member.handle ||
|
|
|
|
|
folks[index].email != payload.member.email
|
|
|
|
|
) {
|
|
|
|
|
folks[index].handle = payload.member.handle;
|
|
|
|
|
folks[index].email = payload.member.email;
|
|
|
|
|
fs.writeJson('site/folks.json', folks);
|
|
|
|
|
} else {
|
|
|
|
|
//no need to save
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
|
message: "You're not logged in, champ"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_.isEqual(settings.global, payload.global)) {
|
|
|
|
|
let bg = payload.global.background;
|
|
|
|
|
payload.global.background = bg.substr(21, bg.length);
|
|
|
|
|
settings.global = payload.global;
|
|
|
|
|
needToUpdate = true;
|
|
|
|
|
} else {
|
|
|
|
|
//no need to save
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_.isEqual(settings.email, payload.email)) {
|
|
|
|
|
settings.email = payload.email;
|
|
|
|
|
needToUpdate = true;
|
|
|
|
|
} else {
|
|
|
|
|
//no need to save
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needToUpdate) {
|
|
|
|
|
fs.writeJson('site/settings.json', settings)
|
|
|
|
|
.then(() => {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.SETTINGS_UPDATED,
|
|
|
|
|
message: 'Settings Saved'
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
//console.error(err);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
//no need to update
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -104,7 +105,7 @@ router.get('/nav', function(req, res) {
|
|
|
|
|
|
|
|
|
|
router.post('/nav-sync', (req, res) => {
|
|
|
|
|
let payload = req.body;
|
|
|
|
|
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
fs.readJson('config/site-settings.json')
|
|
|
|
|
.then(obj => {
|
|
|
|
|
obj.menu = payload;
|
|
|
|
@ -121,10 +122,6 @@ router.post('/nav-sync', (req, res) => {
|
|
|
|
|
.catch(() => {
|
|
|
|
|
//console.error(err);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.json({
|
|
|
|
|
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|