2014-03-02 22:12:08 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
2015-02-13 18:16:36 -05:00
|
|
|
var async = require('async'),
|
2014-02-27 17:16:06 -05:00
|
|
|
nconf = require('nconf'),
|
2014-09-27 19:23:48 -04:00
|
|
|
validator = require('validator'),
|
2014-07-07 17:36:10 -04:00
|
|
|
winston = require('winston'),
|
2015-02-13 18:16:36 -05:00
|
|
|
|
2014-05-22 15:23:19 -04:00
|
|
|
auth = require('../routes/authentication'),
|
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
posts = require('../posts'),
|
|
|
|
|
topics = require('../topics'),
|
|
|
|
|
plugins = require('../plugins'),
|
|
|
|
|
categories = require('../categories'),
|
2015-02-13 18:16:36 -05:00
|
|
|
privileges = require('../privileges'),
|
|
|
|
|
helpers = require('./helpers');
|
2014-02-27 14:56:14 -05:00
|
|
|
|
2014-03-02 22:12:08 -05:00
|
|
|
var Controllers = {
|
2015-02-24 13:02:58 -05:00
|
|
|
posts: require('./posts'),
|
2015-02-13 18:16:36 -05:00
|
|
|
topics: require('./topics'),
|
|
|
|
|
categories: require('./categories'),
|
|
|
|
|
tags: require('./tags'),
|
|
|
|
|
search: require('./search'),
|
|
|
|
|
users: require('./users'),
|
|
|
|
|
groups: require('./groups'),
|
|
|
|
|
accounts: require('./accounts'),
|
|
|
|
|
static: require('./static'),
|
|
|
|
|
api: require('./api'),
|
2015-03-18 03:39:42 +08:00
|
|
|
admin: require('./admin')
|
2014-02-27 14:56:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Controllers.home = function(req, res, next) {
|
2015-02-27 15:00:38 -05:00
|
|
|
var route = meta.config.homePageRoute || 'categories',
|
2015-02-27 15:04:44 -05:00
|
|
|
hook = 'action:homepage.get:' + route;
|
2015-02-27 15:00:38 -05:00
|
|
|
|
|
|
|
|
if (plugins.hasListeners(hook)) {
|
|
|
|
|
plugins.fireHook(hook, {req: req, res: res, next: next});
|
2015-02-17 13:25:13 -05:00
|
|
|
} else {
|
2015-02-27 15:00:38 -05:00
|
|
|
if (route === 'categories') {
|
|
|
|
|
Controllers.categories.list(req, res, next);
|
|
|
|
|
} else if (route === 'recent') {
|
|
|
|
|
Controllers.categories.recent(req, res, next);
|
|
|
|
|
} else if (route === 'popular') {
|
|
|
|
|
Controllers.categories.popular(req, res, next);
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
2015-02-13 18:16:36 -05:00
|
|
|
}
|
2014-02-27 14:56:14 -05:00
|
|
|
};
|
|
|
|
|
|
2014-03-03 17:16:53 -05:00
|
|
|
Controllers.reset = function(req, res, next) {
|
2015-01-29 01:06:48 -05:00
|
|
|
if (req.params.code) {
|
2015-02-08 21:06:38 -05:00
|
|
|
user.reset.validate(req.params.code, function(err, valid) {
|
2015-03-17 15:53:05 -04:00
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
2015-02-08 21:06:38 -05:00
|
|
|
res.render('reset_code', {
|
|
|
|
|
valid: valid,
|
2015-03-17 15:53:05 -04:00
|
|
|
code: req.params.code ? req.params.code : null,
|
2015-02-08 21:06:38 -05:00
|
|
|
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]', url: '/reset'}, {text: '[[reset_password:update_password]]'}])
|
|
|
|
|
});
|
2015-01-29 01:06:48 -05:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.render('reset', {
|
2015-03-17 15:53:05 -04:00
|
|
|
code: req.params.code ? req.params.code : null,
|
2015-01-29 01:06:48 -05:00
|
|
|
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]'}])
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 17:16:53 -05:00
|
|
|
};
|
2014-02-27 14:56:14 -05:00
|
|
|
|
2014-02-27 17:04:41 -05:00
|
|
|
Controllers.login = function(req, res, next) {
|
2014-02-27 16:52:46 -05:00
|
|
|
var data = {},
|
2014-11-12 16:15:44 -05:00
|
|
|
loginStrategies = auth.getLoginStrategies(),
|
2014-02-27 16:52:46 -05:00
|
|
|
emailersPresent = plugins.hasListeners('action:email.send');
|
|
|
|
|
|
2014-11-12 16:15:44 -05:00
|
|
|
data.alternate_logins = loginStrategies.length > 0;
|
|
|
|
|
data.authentication = loginStrategies;
|
2014-02-27 16:52:46 -05:00
|
|
|
data.showResetLink = emailersPresent;
|
2014-10-03 11:34:07 -04:00
|
|
|
data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1;
|
|
|
|
|
data.allowRegistration = parseInt(meta.config.allowRegistration, 10) === 1;
|
2015-02-19 13:24:06 -05:00
|
|
|
data.allowLoginWith = '[[login:' + (meta.config.allowLoginWith || 'username-email') + ']]';
|
2015-01-29 01:06:48 -05:00
|
|
|
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:login]]'}]);
|
2014-08-31 22:41:13 -04:00
|
|
|
data.error = req.flash('error')[0];
|
2014-02-27 16:52:46 -05:00
|
|
|
|
2014-03-09 20:05:14 -04:00
|
|
|
res.render('login', data);
|
2014-02-27 16:52:46 -05:00
|
|
|
};
|
|
|
|
|
|
2014-02-27 17:04:41 -05:00
|
|
|
Controllers.register = function(req, res, next) {
|
2014-09-25 11:29:53 -04:00
|
|
|
if(meta.config.allowRegistration !== undefined && parseInt(meta.config.allowRegistration, 10) === 0) {
|
|
|
|
|
return res.redirect(nconf.get('relative_path') + '/403');
|
|
|
|
|
}
|
2014-03-11 04:10:00 -04:00
|
|
|
|
2014-02-27 16:52:46 -05:00
|
|
|
var data = {},
|
2014-11-12 16:15:44 -05:00
|
|
|
loginStrategies = auth.getLoginStrategies();
|
2014-02-27 16:52:46 -05:00
|
|
|
|
2014-11-12 16:15:44 -05:00
|
|
|
if (loginStrategies.length === 0) {
|
2014-02-27 16:52:46 -05:00
|
|
|
data = {
|
|
|
|
|
'register_window:spansize': 'col-md-12',
|
|
|
|
|
'alternate_logins': false
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
data = {
|
|
|
|
|
'register_window:spansize': 'col-md-6',
|
|
|
|
|
'alternate_logins': true
|
2014-03-02 22:12:08 -05:00
|
|
|
};
|
2014-02-27 16:52:46 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-12 16:15:44 -05:00
|
|
|
data.authentication = loginStrategies;
|
2014-02-27 16:52:46 -05:00
|
|
|
|
|
|
|
|
data.minimumUsernameLength = meta.config.minimumUsernameLength;
|
|
|
|
|
data.maximumUsernameLength = meta.config.maximumUsernameLength;
|
|
|
|
|
data.minimumPasswordLength = meta.config.minimumPasswordLength;
|
|
|
|
|
data.termsOfUse = meta.config.termsOfUse;
|
2015-01-29 01:06:48 -05:00
|
|
|
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]);
|
2014-07-22 22:00:39 -04:00
|
|
|
data.regFormEntry = [];
|
2014-11-14 13:36:37 -05:00
|
|
|
data.error = req.flash('error')[0];
|
2014-03-11 04:10:00 -04:00
|
|
|
|
2014-11-08 14:51:05 -05:00
|
|
|
plugins.fireHook('filter:register.build', {req: req, res: res, templateData: data}, function(err, data) {
|
2015-04-01 14:49:00 -04:00
|
|
|
if (err && global.env === 'development') {
|
2014-05-15 03:06:47 -04:00
|
|
|
winston.warn(JSON.stringify(err));
|
2014-11-08 14:51:05 -05:00
|
|
|
return next(err);
|
2014-05-15 03:06:47 -04:00
|
|
|
}
|
2014-11-08 14:51:05 -05:00
|
|
|
res.render('register', data.templateData);
|
2014-05-15 03:06:47 -04:00
|
|
|
});
|
2014-02-27 16:52:46 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-02-27 17:04:41 -05:00
|
|
|
Controllers.confirmEmail = function(req, res, next) {
|
2015-02-25 14:10:00 -05:00
|
|
|
user.email.confirm(req.params.code, function (err) {
|
|
|
|
|
res.render('confirm', {
|
|
|
|
|
error: err ? err.message : ''
|
|
|
|
|
});
|
2014-02-27 17:04:41 -05:00
|
|
|
});
|
|
|
|
|
};
|
2014-02-27 15:06:39 -05:00
|
|
|
|
2014-02-27 17:16:06 -05:00
|
|
|
Controllers.sitemap = function(req, res, next) {
|
2014-12-01 20:28:36 -05:00
|
|
|
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
|
|
|
|
|
return helpers.notFound(req, res);
|
2014-07-17 01:38:20 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-22 15:23:19 -04:00
|
|
|
var sitemap = require('../sitemap.js');
|
2014-02-27 17:16:06 -05:00
|
|
|
|
|
|
|
|
sitemap.render(function(xml) {
|
|
|
|
|
res.header('Content-Type', 'application/xml');
|
|
|
|
|
res.send(xml);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Controllers.robots = function (req, res) {
|
|
|
|
|
res.set('Content-Type', 'text/plain');
|
|
|
|
|
|
|
|
|
|
if (meta.config["robots.txt"]) {
|
|
|
|
|
res.send(meta.config["robots.txt"]);
|
|
|
|
|
} else {
|
|
|
|
|
res.send("User-agent: *\n" +
|
2014-03-11 19:44:48 -04:00
|
|
|
"Disallow: " + nconf.get('relative_path') + "/admin/\n" +
|
2014-02-27 17:16:06 -05:00
|
|
|
"Sitemap: " + nconf.get('url') + "/sitemap.xml");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-28 14:04:21 -05:00
|
|
|
Controllers.outgoing = function(req, res, next) {
|
|
|
|
|
var url = req.query.url,
|
|
|
|
|
data = {
|
|
|
|
|
url: url,
|
2015-01-29 01:06:48 -05:00
|
|
|
title: meta.config.title,
|
|
|
|
|
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[notifications:outgoing_link]]'}])
|
2014-02-28 14:04:21 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (url) {
|
2014-03-09 20:05:14 -04:00
|
|
|
res.render('outgoing', data);
|
2014-02-28 14:04:21 -05:00
|
|
|
} else {
|
2014-11-16 00:01:20 -05:00
|
|
|
res.status(404).redirect(nconf.get('relative_path') + '/404');
|
2014-02-28 14:04:21 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-14 12:17:24 -05:00
|
|
|
Controllers.termsOfUse = function(req, res, next) {
|
|
|
|
|
if (!meta.config.termsOfUse) {
|
2014-12-01 20:28:36 -05:00
|
|
|
return helpers.notFound(req, res);
|
2014-11-14 12:17:24 -05:00
|
|
|
}
|
|
|
|
|
res.render('tos', {termsOfUse: meta.config.termsOfUse});
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-10 20:31:57 +01:00
|
|
|
module.exports = Controllers;
|