Compose without scripts

This commit is contained in:
André Zanghelini
2017-06-03 18:08:15 -03:00
parent a49a9a07b3
commit 80ccc6fd58
3 changed files with 74 additions and 0 deletions

View File

@@ -14,6 +14,20 @@ var middleware = require('../middleware');
var helpers = module.exports;
helpers.noScriptErrors = function (req, res, error, httpStatus) {
var middleware = require('../middleware');
var httpStatusString = httpStatus.toString();
middleware.buildHeader(req, res, function () {
res.status(httpStatus).render(httpStatusString, {
path: req.path,
loggedIn: true,
error: error,
returnLink: true,
title: '[[global:' + httpStatusString + '.title]]',
});
});
};
helpers.notAllowed = function (req, res, error) {
plugins.fireHook('filter:helpers.notAllowed', {
req: req,

View File

@@ -7,6 +7,7 @@ var validator = require('validator');
var meta = require('../meta');
var user = require('../user');
var plugins = require('../plugins');
var topics = require('../topics');
var helpers = require('./helpers');
var Controllers = module.exports;
@@ -279,6 +280,63 @@ Controllers.compose = function (req, res, next) {
});
};
Controllers.composePost = function (req, res, next) {
var body = req.body;
var data = {
uid: req.uid,
req: req,
timestamp: Date.now(),
content: body.content,
};
if (!data.content) {
return helpers.noScriptErrors(req, res, '[[error:invalid-data]]', 400);
}
if (body.tid) {
data.tid = body.tid;
async.waterfall([
function (next) {
topics.reply(data, next);
},
function (postData, next) {
next(null, postData);
user.updateOnlineUsers(postData.uid);
res.redirect(nconf.get('relative_path') + '/post/' + postData.pid);
},
], function (err) {
if (err) {
return helpers.noScriptErrors(req, res, err.message, 400);
}
next(err);
});
} else if (body.cid) {
data.cid = body.cid;
data.title = body.title;
data.tags = [];
data.thumb = '';
async.waterfall([
function (next) {
topics.post(data, next);
},
function (result, next) {
next(null, result.topicData);
res.redirect(nconf.get('relative_path') + '/topic/' + result.topicData.slug);
},
], function (err) {
if (err) {
return helpers.noScriptErrors(req, res, err.message, 400);
}
next(err);
});
}
};
Controllers.confirmEmail = function (req, res) {
user.email.confirm(req.params.code, function (err) {
res.render('confirm', {

View File

@@ -34,6 +34,8 @@ function mainRoutes(app, middleware, controllers) {
setupPageRoute(app, '/search', middleware, [], controllers.search.search);
setupPageRoute(app, '/reset/:code?', middleware, [], controllers.reset);
setupPageRoute(app, '/tos', middleware, [], controllers.termsOfUse);
app.post('/compose', middleware.applyCSRF, controllers.composePost);
}
function modRoutes(app, middleware, controllers) {