|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var validator = require('validator');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
var user = require('../user');
|
|
|
|
@ -205,7 +206,7 @@ Controllers.compose = function(req, res, next) {
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Controllers.confirmEmail = function(req, res, next) {
|
|
|
|
|
Controllers.confirmEmail = function(req, res) {
|
|
|
|
|
user.email.confirm(req.params.code, function (err) {
|
|
|
|
|
res.render('confirm', {
|
|
|
|
|
error: err ? err.message : '',
|
|
|
|
@ -217,6 +218,10 @@ Controllers.confirmEmail = function(req, res, next) {
|
|
|
|
|
Controllers.sitemap = {};
|
|
|
|
|
Controllers.sitemap.render = function(req, res, next) {
|
|
|
|
|
sitemap.render(function(err, tplData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Controllers.render('sitemap', tplData, function(err, xml) {
|
|
|
|
|
res.header('Content-Type', 'application/xml');
|
|
|
|
|
res.send(xml);
|
|
|
|
@ -327,7 +332,7 @@ Controllers.manifest = function(req, res) {
|
|
|
|
|
res.status(200).json(manifest);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Controllers.outgoing = function(req, res, next) {
|
|
|
|
|
Controllers.outgoing = function(req, res) {
|
|
|
|
|
var url = req.query.url;
|
|
|
|
|
var data = {
|
|
|
|
|
url: validator.escape(String(url)),
|
|
|
|
@ -349,4 +354,68 @@ Controllers.termsOfUse = function(req, res, next) {
|
|
|
|
|
res.render('tos', {termsOfUse: meta.config.termsOfUse});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Controllers.handle404 = function(req, res) {
|
|
|
|
|
var relativePath = nconf.get('relative_path');
|
|
|
|
|
var isLanguage = new RegExp('^' + relativePath + '/language/.*/.*.json');
|
|
|
|
|
var isClientScript = new RegExp('^' + relativePath + '\\/src\\/.+\\.js');
|
|
|
|
|
|
|
|
|
|
if (plugins.hasListeners('action:meta.override404')) {
|
|
|
|
|
return plugins.fireHook('action:meta.override404', {
|
|
|
|
|
req: req,
|
|
|
|
|
res: res,
|
|
|
|
|
error: {}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isClientScript.test(req.url)) {
|
|
|
|
|
res.type('text/javascript').status(200).send('');
|
|
|
|
|
} else if (isLanguage.test(req.url)) {
|
|
|
|
|
res.status(200).json({});
|
|
|
|
|
} else if (req.path.startsWith(relativePath + '/uploads') || (req.get('accept') && req.get('accept').indexOf('text/html') === -1) || req.path === '/favicon.ico') {
|
|
|
|
|
res.sendStatus(404);
|
|
|
|
|
} else if (req.accepts('html')) {
|
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
|
winston.warn('Route requested but not found: ' + req.url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.status(404);
|
|
|
|
|
|
|
|
|
|
if (res.locals.isAPI) {
|
|
|
|
|
return res.json({path: validator.escape(req.path.replace(/^\/api/, '') || ''), title: '[[global:404.title]]'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req.app.locals.middleware.buildHeader(req, res, function() {
|
|
|
|
|
res.render('404', {path: validator.escape(req.path || ''), title: '[[global:404.title]]'});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.status(404).type('txt').send('Not found');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Controllers.handleErrors = function(err, req, res, next) {
|
|
|
|
|
switch (err.code) {
|
|
|
|
|
case 'EBADCSRFTOKEN':
|
|
|
|
|
winston.error(req.path + '\n', err.message);
|
|
|
|
|
return res.sendStatus(403);
|
|
|
|
|
case 'blacklisted-ip':
|
|
|
|
|
return res.status(403).type('text/plain').send(err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parseInt(err.status, 10) === 302 && err.path) {
|
|
|
|
|
return res.locals.isAPI ? res.status(302).json(err.path) : res.redirect(err.path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
winston.error(req.path + '\n', err.stack);
|
|
|
|
|
|
|
|
|
|
res.status(err.status || 500);
|
|
|
|
|
|
|
|
|
|
if (res.locals.isAPI) {
|
|
|
|
|
res.json({path: validator.escape(req.path || ''), error: err.message});
|
|
|
|
|
} else {
|
|
|
|
|
req.app.locals.middleware.buildHeader(req, res, function() {
|
|
|
|
|
res.render('500', {path: validator.escape(String(req.path || '')), error: validator.escape(err.message)});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = Controllers;
|
|
|
|
|