You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
8.1 KiB
JavaScript

"use strict";
10 years ago
var async = require('async'),
nconf = require('nconf'),
11 years ago
validator = require('validator'),
11 years ago
winston = require('winston'),
10 years ago
11 years ago
meta = require('../meta'),
user = require('../user'),
posts = require('../posts'),
topics = require('../topics'),
plugins = require('../plugins'),
Squashed commit of the following: commit 56582bc9eee5d81a01f42a28808b617b9c96873a Author: Julian Lam <[email protected]> Date: Tue Oct 27 05:21:11 2015 -0400 added missing template commit 6462a1626e7d8d77210b6e10eace5c9214335f33 Author: Julian Lam <[email protected]> Date: Tue Oct 27 05:19:07 2015 -0400 sitemap index commit 3cfd56f1fbc8e03405dc394375bf5ff6eef21322 Author: Julian Lam <[email protected]> Date: Tue Oct 27 04:47:52 2015 -0400 sitemap routes, controllers, and library methods for pages, categories, and topics commit e58e07c0881bdbe16d503b4679b85f761b02163c Author: Julian Lam <[email protected]> Date: Tue Oct 27 04:07:39 2015 -0400 added groups to sitemap commit 7ee584b6327ea79f4b1f465c32da28d01c75908f Author: Julian Lam <[email protected]> Date: Tue Oct 27 01:43:06 2015 -0400 If notification dropdown is double-clicked, all notifications are marked read commit 488f147bef395233edb697a3895df0da7ee5ed0d Author: barisusakli <[email protected]> Date: Mon Oct 26 22:39:19 2015 -0400 closes #3781 commit 5e1bd58a022b1aaeedd7ab83c3655b3c16c611a0 Author: barisusakli <[email protected]> Date: Mon Oct 26 22:28:30 2015 -0400 closes #3782 commit 57d39802671612185e86977b5c237f850fe80206 Author: barisusakli <[email protected]> Date: Mon Oct 26 22:16:08 2015 -0400 closes #3790 commit 555c5b82da3ee30eab3fb21b2474eba834556741 Author: barisusakli <[email protected]> Date: Mon Oct 26 21:19:20 2015 -0400 check user settings commit 5454862c1c81525bb096466a547557cfb0f9a2b7 Author: barisusakli <[email protected]> Date: Mon Oct 26 20:26:02 2015 -0400 wait for all callbacks when creating tags commit 051c5077eb49937a8cac33b6b689c0902acfca51 Merge: 839fd93 e0e04ef Author: Barış Soner Uşaklı <[email protected]> Date: Mon Oct 26 09:54:12 2015 -0400 Merge pull request #3792 from drlogout/master Fixed wrong method name in socket.io/groups.js from isAdmin to isAdmi… commit e0e04ef8920e61f3bf411903b5a5c1f5198e1698 Author: Christian Nolte <[email protected]> Date: Mon Oct 26 14:50:32 2015 +0100 Fixed wrong method name in socket.io/groups.js from isAdmin to isAdministrator commit 839fd935ada8d6c88eb38adbd7435679a9103875 Author: barisusakli <[email protected]> Date: Sun Oct 25 21:54:35 2015 -0400 add back thread tools filter commit 37060bf1a3b75f6d74af9501344c4bd06d343db2 Merge: 5820a19 bf918bd Author: Barış Soner Uşaklı <[email protected]> Date: Sun Oct 25 18:13:06 2015 -0400 Merge pull request #3787 from cubehouse/patch-1 Upgrade script fails on some consoles commit 5820a193f60bcf0398ab1f981192cc1908f277cc Author: barisusakli <[email protected]> Date: Sun Oct 25 17:04:46 2015 -0400 closes #3789 commit 0d88d52557bf187c3b4d2b78f6da49d52952e9d1 Author: barisusakli <[email protected]> Date: Sun Oct 25 17:03:33 2015 -0400 up theme commit 9bc43ba5e1e8ca145615bd07fff1560bc7f3eb6e Author: barisusakli <[email protected]> Date: Sun Oct 25 16:57:42 2015 -0400 closes #3788 commit aafd4b698456864fb41c365d3202a7890643fd72 Author: barisusakli <[email protected]> Date: Sun Oct 25 15:56:17 2015 -0400 closes #3786 commit bf918bd016f645b9d307e4314943f787082b8627 Author: James Holding <[email protected]> Date: Sun Oct 25 10:14:00 2015 +0000 Upgrade script fails on some consoles The upgrade script errors/fails on some consoles if the stdout.columns isn't set (my console did this when upgrading a Docker instance of NodeBB). Checking for stdout.columns before using, falling back to a couple of spaces for slightly prettiness if we can't work out the console width.
9 years ago
sitemap = require('../sitemap'),
11 years ago
categories = require('../categories'),
10 years ago
privileges = require('../privileges'),
helpers = require('./helpers');
11 years ago
var Controllers = {
10 years ago
topics: require('./topics'),
categories: require('./categories'),
unread: require('./unread'),
recent: require('./recent'),
popular: require('./popular'),
10 years ago
tags: require('./tags'),
search: require('./search'),
users: require('./users'),
groups: require('./groups'),
accounts: require('./accounts'),
10 years ago
authentication: require('./authentication'),
10 years ago
api: require('./api'),
10 years ago
admin: require('./admin')
11 years ago
};
Controllers.home = function(req, res, next) {
var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories',
hook = 'action:homepage.get:' + route;
if (plugins.hasListeners(hook)) {
plugins.fireHook(hook, {req: req, res: res, next: next});
10 years ago
} else {
if (route === 'categories' || route === '/') {
Controllers.categories.list(req, res, next);
} else if (route === 'recent') {
Controllers.recent.get(req, res, next);
} else if (route === 'popular') {
Controllers.popular.get(req, res, next);
} else {
res.redirect(route);
}
10 years ago
}
11 years ago
};
Controllers.reset = function(req, res, next) {
10 years ago
if (req.params.code) {
10 years ago
user.reset.validate(req.params.code, function(err, valid) {
if (err) {
return next(err);
}
10 years ago
res.render('reset_code', {
valid: valid,
10 years ago
displayExpiryNotice: req.session.passwordExpired,
code: req.params.code ? req.params.code : null,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]', url: '/reset'}, {text: '[[reset_password:update_password]]'}]),
title: '[[pages:reset]]'
10 years ago
});
10 years ago
delete req.session.passwordExpired;
10 years ago
});
} else {
res.render('reset', {
code: req.params.code ? req.params.code : null,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]'}]),
title: '[[pages:reset]]'
10 years ago
});
}
};
11 years ago
Controllers.login = function(req, res, next) {
var data = {},
10 years ago
loginStrategies = require('../routes/authentication').getLoginStrategies(),
10 years ago
emailersPresent = plugins.hasListeners('filter:email.send');
10 years ago
var registrationType = meta.config.registrationType || 'normal';
10 years ago
data.alternate_logins = loginStrategies.length > 0;
data.authentication = loginStrategies;
data.showResetLink = emailersPresent;
10 years ago
data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1 || parseInt(req.query.local, 10) === 1;
10 years ago
data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval';
10 years ago
data.allowLoginWith = '[[login:' + (meta.config.allowLoginWith || 'username-email') + ']]';
10 years ago
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:login]]'}]);
data.error = req.flash('error')[0];
data.title = '[[pages:login]]';
res.render('login', data);
};
Controllers.register = function(req, res, next) {
10 years ago
var registrationType = meta.config.registrationType || 'normal';
if (registrationType === 'disabled') {
10 years ago
return next();
11 years ago
}
11 years ago
10 years ago
async.waterfall([
function(next) {
if (registrationType === 'invite-only') {
user.verifyInvitation(req.query, next);
} else {
next();
}
},
function(next) {
10 years ago
plugins.fireHook('filter:parse.post', {postData: {content: meta.config.termsOfUse}}, next);
},
function(tos, next) {
10 years ago
var loginStrategies = require('../routes/authentication').getLoginStrategies();
var data = {
'register_window:spansize': loginStrategies.length ? 'col-md-6' : 'col-md-12',
'alternate_logins': !!loginStrategies.length
};
data.authentication = loginStrategies;
data.minimumUsernameLength = meta.config.minimumUsernameLength;
data.maximumUsernameLength = meta.config.maximumUsernameLength;
data.minimumPasswordLength = meta.config.minimumPasswordLength;
10 years ago
data.termsOfUse = tos.postData.content;
10 years ago
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]);
data.regFormEntry = [];
data.error = req.flash('error')[0];
data.title = '[[pages:register]]';
10 years ago
plugins.fireHook('filter:register.build', {req: req, res: res, templateData: data}, next);
}
], function(err, data) {
if (err) {
return next(err);
}
res.render('register', data.templateData);
});
};
10 years ago
Controllers.compose = function(req, res, next) {
10 years ago
if (req.query.p && !res.locals.isAPI) {
if (req.query.p.startsWith(nconf.get('relative_path'))) {
req.query.p = req.query.p.replace(nconf.get('relative_path'), '');
}
10 years ago
return helpers.redirect(res, req.query.p);
10 years ago
}
res.render('', {});
10 years ago
};
Controllers.confirmEmail = function(req, res, next) {
user.email.confirm(req.params.code, function (err) {
res.render('confirm', {
error: err ? err.message : ''
});
});
};
11 years ago
Squashed commit of the following: commit 56582bc9eee5d81a01f42a28808b617b9c96873a Author: Julian Lam <[email protected]> Date: Tue Oct 27 05:21:11 2015 -0400 added missing template commit 6462a1626e7d8d77210b6e10eace5c9214335f33 Author: Julian Lam <[email protected]> Date: Tue Oct 27 05:19:07 2015 -0400 sitemap index commit 3cfd56f1fbc8e03405dc394375bf5ff6eef21322 Author: Julian Lam <[email protected]> Date: Tue Oct 27 04:47:52 2015 -0400 sitemap routes, controllers, and library methods for pages, categories, and topics commit e58e07c0881bdbe16d503b4679b85f761b02163c Author: Julian Lam <[email protected]> Date: Tue Oct 27 04:07:39 2015 -0400 added groups to sitemap commit 7ee584b6327ea79f4b1f465c32da28d01c75908f Author: Julian Lam <[email protected]> Date: Tue Oct 27 01:43:06 2015 -0400 If notification dropdown is double-clicked, all notifications are marked read commit 488f147bef395233edb697a3895df0da7ee5ed0d Author: barisusakli <[email protected]> Date: Mon Oct 26 22:39:19 2015 -0400 closes #3781 commit 5e1bd58a022b1aaeedd7ab83c3655b3c16c611a0 Author: barisusakli <[email protected]> Date: Mon Oct 26 22:28:30 2015 -0400 closes #3782 commit 57d39802671612185e86977b5c237f850fe80206 Author: barisusakli <[email protected]> Date: Mon Oct 26 22:16:08 2015 -0400 closes #3790 commit 555c5b82da3ee30eab3fb21b2474eba834556741 Author: barisusakli <[email protected]> Date: Mon Oct 26 21:19:20 2015 -0400 check user settings commit 5454862c1c81525bb096466a547557cfb0f9a2b7 Author: barisusakli <[email protected]> Date: Mon Oct 26 20:26:02 2015 -0400 wait for all callbacks when creating tags commit 051c5077eb49937a8cac33b6b689c0902acfca51 Merge: 839fd93 e0e04ef Author: Barış Soner Uşaklı <[email protected]> Date: Mon Oct 26 09:54:12 2015 -0400 Merge pull request #3792 from drlogout/master Fixed wrong method name in socket.io/groups.js from isAdmin to isAdmi… commit e0e04ef8920e61f3bf411903b5a5c1f5198e1698 Author: Christian Nolte <[email protected]> Date: Mon Oct 26 14:50:32 2015 +0100 Fixed wrong method name in socket.io/groups.js from isAdmin to isAdministrator commit 839fd935ada8d6c88eb38adbd7435679a9103875 Author: barisusakli <[email protected]> Date: Sun Oct 25 21:54:35 2015 -0400 add back thread tools filter commit 37060bf1a3b75f6d74af9501344c4bd06d343db2 Merge: 5820a19 bf918bd Author: Barış Soner Uşaklı <[email protected]> Date: Sun Oct 25 18:13:06 2015 -0400 Merge pull request #3787 from cubehouse/patch-1 Upgrade script fails on some consoles commit 5820a193f60bcf0398ab1f981192cc1908f277cc Author: barisusakli <[email protected]> Date: Sun Oct 25 17:04:46 2015 -0400 closes #3789 commit 0d88d52557bf187c3b4d2b78f6da49d52952e9d1 Author: barisusakli <[email protected]> Date: Sun Oct 25 17:03:33 2015 -0400 up theme commit 9bc43ba5e1e8ca145615bd07fff1560bc7f3eb6e Author: barisusakli <[email protected]> Date: Sun Oct 25 16:57:42 2015 -0400 closes #3788 commit aafd4b698456864fb41c365d3202a7890643fd72 Author: barisusakli <[email protected]> Date: Sun Oct 25 15:56:17 2015 -0400 closes #3786 commit bf918bd016f645b9d307e4314943f787082b8627 Author: James Holding <[email protected]> Date: Sun Oct 25 10:14:00 2015 +0000 Upgrade script fails on some consoles The upgrade script errors/fails on some consoles if the stdout.columns isn't set (my console did this when upgrading a Docker instance of NodeBB). Checking for stdout.columns before using, falling back to a couple of spaces for slightly prettiness if we can't work out the console width.
9 years ago
Controllers.sitemap = {};
Controllers.sitemap.render = function(req, res, next) {
sitemap.render(function(err, tplData) {
Controllers.render('sitemap', tplData, function(err, xml) {
res.header('Content-Type', 'application/xml');
res.send(xml);
});
})
};
Controllers.sitemap.getPages = function(req, res, next) {
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
return next();
}
sitemap.getPages(function(err, xml) {
if (err) {
return next(err);
}
res.header('Content-Type', 'application/xml');
res.send(xml);
});
};
Controllers.sitemap.getCategories = function(req, res, next) {
10 years ago
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
10 years ago
return next();
}
Squashed commit of the following: commit 56582bc9eee5d81a01f42a28808b617b9c96873a Author: Julian Lam <[email protected]> Date: Tue Oct 27 05:21:11 2015 -0400 added missing template commit 6462a1626e7d8d77210b6e10eace5c9214335f33 Author: Julian Lam <[email protected]> Date: Tue Oct 27 05:19:07 2015 -0400 sitemap index commit 3cfd56f1fbc8e03405dc394375bf5ff6eef21322 Author: Julian Lam <[email protected]> Date: Tue Oct 27 04:47:52 2015 -0400 sitemap routes, controllers, and library methods for pages, categories, and topics commit e58e07c0881bdbe16d503b4679b85f761b02163c Author: Julian Lam <[email protected]> Date: Tue Oct 27 04:07:39 2015 -0400 added groups to sitemap commit 7ee584b6327ea79f4b1f465c32da28d01c75908f Author: Julian Lam <[email protected]> Date: Tue Oct 27 01:43:06 2015 -0400 If notification dropdown is double-clicked, all notifications are marked read commit 488f147bef395233edb697a3895df0da7ee5ed0d Author: barisusakli <[email protected]> Date: Mon Oct 26 22:39:19 2015 -0400 closes #3781 commit 5e1bd58a022b1aaeedd7ab83c3655b3c16c611a0 Author: barisusakli <[email protected]> Date: Mon Oct 26 22:28:30 2015 -0400 closes #3782 commit 57d39802671612185e86977b5c237f850fe80206 Author: barisusakli <[email protected]> Date: Mon Oct 26 22:16:08 2015 -0400 closes #3790 commit 555c5b82da3ee30eab3fb21b2474eba834556741 Author: barisusakli <[email protected]> Date: Mon Oct 26 21:19:20 2015 -0400 check user settings commit 5454862c1c81525bb096466a547557cfb0f9a2b7 Author: barisusakli <[email protected]> Date: Mon Oct 26 20:26:02 2015 -0400 wait for all callbacks when creating tags commit 051c5077eb49937a8cac33b6b689c0902acfca51 Merge: 839fd93 e0e04ef Author: Barış Soner Uşaklı <[email protected]> Date: Mon Oct 26 09:54:12 2015 -0400 Merge pull request #3792 from drlogout/master Fixed wrong method name in socket.io/groups.js from isAdmin to isAdmi… commit e0e04ef8920e61f3bf411903b5a5c1f5198e1698 Author: Christian Nolte <[email protected]> Date: Mon Oct 26 14:50:32 2015 +0100 Fixed wrong method name in socket.io/groups.js from isAdmin to isAdministrator commit 839fd935ada8d6c88eb38adbd7435679a9103875 Author: barisusakli <[email protected]> Date: Sun Oct 25 21:54:35 2015 -0400 add back thread tools filter commit 37060bf1a3b75f6d74af9501344c4bd06d343db2 Merge: 5820a19 bf918bd Author: Barış Soner Uşaklı <[email protected]> Date: Sun Oct 25 18:13:06 2015 -0400 Merge pull request #3787 from cubehouse/patch-1 Upgrade script fails on some consoles commit 5820a193f60bcf0398ab1f981192cc1908f277cc Author: barisusakli <[email protected]> Date: Sun Oct 25 17:04:46 2015 -0400 closes #3789 commit 0d88d52557bf187c3b4d2b78f6da49d52952e9d1 Author: barisusakli <[email protected]> Date: Sun Oct 25 17:03:33 2015 -0400 up theme commit 9bc43ba5e1e8ca145615bd07fff1560bc7f3eb6e Author: barisusakli <[email protected]> Date: Sun Oct 25 16:57:42 2015 -0400 closes #3788 commit aafd4b698456864fb41c365d3202a7890643fd72 Author: barisusakli <[email protected]> Date: Sun Oct 25 15:56:17 2015 -0400 closes #3786 commit bf918bd016f645b9d307e4314943f787082b8627 Author: James Holding <[email protected]> Date: Sun Oct 25 10:14:00 2015 +0000 Upgrade script fails on some consoles The upgrade script errors/fails on some consoles if the stdout.columns isn't set (my console did this when upgrading a Docker instance of NodeBB). Checking for stdout.columns before using, falling back to a couple of spaces for slightly prettiness if we can't work out the console width.
9 years ago
sitemap.getCategories(function(err, xml) {
if (err) {
return next(err);
}
res.header('Content-Type', 'application/xml');
res.send(xml);
});
};
Controllers.sitemap.getTopicPage = function(req, res, next) {
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
return next();
}
sitemap.getTopicPage(parseInt(req.params[0], 10), function(err, xml) {
if (err) {
return next(err);
} else if (!xml) {
return next();
}
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" +
"Disallow: " + nconf.get('relative_path') + "/admin/\n" +
"Sitemap: " + nconf.get('url') + "/sitemap.xml");
}
};
Controllers.manifest = function(req, res) {
var manifest = {
name: meta.config.title || 'NodeBB',
start_url: nconf.get('relative_path') + '/',
display: 'standalone',
orientation: 'portrait',
icons: []
};
if (meta.config['brand:touchIcon']) {
manifest.icons.push({
src: nconf.get('relative_path') + '/uploads/system/touchicon-36.png',
sizes: '36x36',
type: 'image/png',
density: 0.75
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-48.png',
sizes: '48x48',
type: 'image/png',
density: 1.0
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-72.png',
sizes: '72x72',
type: 'image/png',
density: 1.5
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-96.png',
sizes: '96x96',
type: 'image/png',
density: 2.0
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-144.png',
sizes: '144x144',
type: 'image/png',
density: 3.0
}, {
src: nconf.get('relative_path') + '/uploads/system/touchicon-192.png',
sizes: '192x192',
type: 'image/png',
density: 4.0
})
}
res.status(200).json(manifest);
};
Controllers.outgoing = function(req, res, next) {
var url = req.query.url,
data = {
url: validator.escape(url),
10 years ago
title: meta.config.title,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[notifications:outgoing_link]]'}])
};
if (url) {
res.render('outgoing', data);
} else {
res.status(404).redirect(nconf.get('relative_path') + '/404');
}
};
10 years ago
Controllers.termsOfUse = function(req, res, next) {
if (!meta.config.termsOfUse) {
10 years ago
return next();
10 years ago
}
res.render('tos', {termsOfUse: meta.config.termsOfUse});
};
module.exports = Controllers;