| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2014-03-02 22:12:08 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | var async = require('async'); | 
					
						
							|  |  |  | var nconf = require('nconf'); | 
					
						
							|  |  |  | var validator = require('validator'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var meta = require('../meta'); | 
					
						
							|  |  |  | var user = require('../user'); | 
					
						
							|  |  |  | var plugins = require('../plugins'); | 
					
						
							| 
									
										
										
										
											2017-07-20 08:51:04 -04:00
										 |  |  | var topics = require('../topics'); | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | var helpers = require('./helpers'); | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | var Controllers = module.exports; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Controllers.topics = require('./topics'); | 
					
						
							|  |  |  | Controllers.posts = require('./posts'); | 
					
						
							|  |  |  | Controllers.categories = require('./categories'); | 
					
						
							|  |  |  | Controllers.category = require('./category'); | 
					
						
							|  |  |  | Controllers.unread = require('./unread'); | 
					
						
							|  |  |  | Controllers.recent = require('./recent'); | 
					
						
							|  |  |  | Controllers.popular = require('./popular'); | 
					
						
							|  |  |  | Controllers.tags = require('./tags'); | 
					
						
							|  |  |  | Controllers.search = require('./search'); | 
					
						
							| 
									
										
										
										
											2017-03-02 16:11:11 +03:00
										 |  |  | Controllers.user = require('./user'); | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | Controllers.users = require('./users'); | 
					
						
							|  |  |  | Controllers.groups = require('./groups'); | 
					
						
							|  |  |  | Controllers.accounts = require('./accounts'); | 
					
						
							|  |  |  | Controllers.authentication = require('./authentication'); | 
					
						
							|  |  |  | Controllers.api = require('./api'); | 
					
						
							|  |  |  | Controllers.admin = require('./admin'); | 
					
						
							|  |  |  | Controllers.globalMods = require('./globalmods'); | 
					
						
							|  |  |  | Controllers.mods = require('./mods'); | 
					
						
							|  |  |  | Controllers.sitemap = require('./sitemap'); | 
					
						
							| 
									
										
										
										
											2017-03-06 21:00:20 +01:00
										 |  |  | Controllers.osd = require('./osd'); | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | Controllers['404'] = require('./404'); | 
					
						
							|  |  |  | Controllers.errors = require('./errors'); | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.home = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-04-20 16:12:55 -04:00
										 |  |  | 	var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories'; | 
					
						
							| 
									
										
										
										
											2015-02-27 15:00:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	user.getSettings(req.uid, function (err, settings) { | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-07 18:55:30 +00:00
										 |  |  | 		if (parseInt(meta.config.allowUserHomePage, 10) === 1 && settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') { | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 			route = settings.homePageRoute || route; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var hook = 'action:homepage.get:' + route; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (plugins.hasListeners(hook)) { | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 			return plugins.fireHook(hook, { | 
					
						
							|  |  |  | 				req: req, | 
					
						
							|  |  |  | 				res: res, | 
					
						
							|  |  |  | 				next: next, | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (route === 'categories' || route === '/') { | 
					
						
							|  |  |  | 			Controllers.categories.list(req, res, next); | 
					
						
							| 
									
										
										
										
											2016-07-15 12:39:54 +03:00
										 |  |  | 		} else if (route === 'unread') { | 
					
						
							|  |  |  | 			Controllers.unread.get(req, res, next); | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 		} else if (route === 'recent') { | 
					
						
							|  |  |  | 			Controllers.recent.get(req, res, next); | 
					
						
							|  |  |  | 		} else if (route === 'popular') { | 
					
						
							|  |  |  | 			Controllers.popular.get(req, res, next); | 
					
						
							| 
									
										
										
										
											2015-02-27 15:00:38 -05:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 			var match = /^category\/(\d+)\/(.*)$/.exec(route); | 
					
						
							| 
									
										
										
										
											2015-12-01 12:59:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 			if (match) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 				req.params.topic_index = '1'; | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 				req.params.category_id = match[1]; | 
					
						
							|  |  |  | 				req.params.slug = match[2]; | 
					
						
							|  |  |  | 				Controllers.category.get(req, res, next); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				res.redirect(route); | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-02-27 15:00:38 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.reset = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 	if (req.params.code) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02: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-04-01 17:26:22 -04:00
										 |  |  | 				displayExpiryNotice: req.session.passwordExpired, | 
					
						
							| 
									
										
										
										
											2016-10-18 15:32:28 +03:00
										 |  |  | 				code: req.params.code, | 
					
						
							| 
									
										
										
										
											2016-02-10 12:53:39 +02:00
										 |  |  | 				minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10), | 
					
						
							| 
									
										
										
										
											2017-04-07 21:39:22 +00:00
										 |  |  | 				breadcrumbs: helpers.buildBreadcrumbs([ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						text: '[[reset_password:reset_password]]', | 
					
						
							|  |  |  | 						url: '/reset', | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						text: '[[reset_password:update_password]]', | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				]), | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				title: '[[pages:reset]]', | 
					
						
							| 
									
										
										
										
											2015-02-08 21:06:38 -05:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-04-01 17:26:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			delete req.session.passwordExpired; | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		res.render('reset', { | 
					
						
							| 
									
										
										
										
											2016-10-18 15:32:28 +03:00
										 |  |  | 			code: null, | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 			breadcrumbs: helpers.buildBreadcrumbs([{ | 
					
						
							|  |  |  | 				text: '[[reset_password:reset_password]]', | 
					
						
							|  |  |  | 			}]), | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			title: '[[pages:reset]]', | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-03 17:16:53 -05:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.login = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 	var data = {}; | 
					
						
							|  |  |  | 	var loginStrategies = require('../routes/authentication').getLoginStrategies(); | 
					
						
							|  |  |  | 	var registrationType = meta.config.registrationType || 'normal'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var allowLoginWith = (meta.config.allowLoginWith || 'username-email'); | 
					
						
							| 
									
										
										
										
											2016-11-16 19:57:23 -05:00
										 |  |  | 	var returnTo = (req.headers['x-return-to'] || '').replace(nconf.get('base_url'), ''); | 
					
						
							| 
									
										
										
										
											2015-06-27 21:26:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	var errorText; | 
					
						
							|  |  |  | 	if (req.query.error === 'csrf-invalid') { | 
					
						
							|  |  |  | 		errorText = '[[error:csrf-invalid]]'; | 
					
						
							| 
									
										
										
										
											2016-07-25 12:15:02 -04:00
										 |  |  | 	} else if (req.query.error) { | 
					
						
							| 
									
										
										
										
											2016-08-30 13:19:04 +03:00
										 |  |  | 		errorText = validator.escape(String(req.query.error)); | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-25 16:52:03 -04:00
										 |  |  | 	if (returnTo) { | 
					
						
							|  |  |  | 		req.session.returnTo = returnTo; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-12 16:15:44 -05:00
										 |  |  | 	data.alternate_logins = loginStrategies.length > 0; | 
					
						
							|  |  |  | 	data.authentication = loginStrategies; | 
					
						
							| 
									
										
										
										
											2015-04-22 12:13:14 -04:00
										 |  |  | 	data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1 || parseInt(req.query.local, 10) === 1; | 
					
						
							| 
									
										
										
										
											2016-07-25 09:56:29 -05:00
										 |  |  | 	data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip'; | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 	data.allowLoginWith = '[[login:' + allowLoginWith + ']]'; | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 	data.breadcrumbs = helpers.buildBreadcrumbs([{ | 
					
						
							|  |  |  | 		text: '[[global:login]]', | 
					
						
							|  |  |  | 	}]); | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	data.error = req.flash('error')[0] || errorText; | 
					
						
							| 
									
										
										
										
											2015-08-26 15:54:54 -04:00
										 |  |  | 	data.title = '[[pages:login]]'; | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:58:14 -04:00
										 |  |  | 	if (!data.allowLocalLogin && !data.allowRegistration && data.alternate_logins && data.authentication.length === 1) { | 
					
						
							| 
									
										
										
										
											2016-07-12 11:39:51 -04:00
										 |  |  | 		if (res.locals.isAPI) { | 
					
						
							|  |  |  | 			return helpers.redirect(res, { | 
					
						
							| 
									
										
										
										
											2017-03-07 14:35:38 -05:00
										 |  |  | 				external: nconf.get('relative_path') + data.authentication[0].url, | 
					
						
							| 
									
										
										
										
											2016-07-12 11:39:51 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 14:27:26 -07:00
										 |  |  | 		return res.redirect(nconf.get('relative_path') + data.authentication[0].url); | 
					
						
							| 
									
										
										
										
											2016-04-13 11:58:14 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 	if (req.uid) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		user.getUserFields(req.uid, ['username', 'email'], function (err, user) { | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return next(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			data.username = allowLoginWith === 'email' ? user.email : user.username; | 
					
						
							| 
									
										
										
										
											2017-07-22 19:05:22 -04:00
										 |  |  | 			data.alternate_logins = false; | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 			res.render('login', data); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		res.render('login', data); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.register = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2015-06-27 21:26:19 -04:00
										 |  |  | 	var registrationType = meta.config.registrationType || 'normal'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (registrationType === 'disabled') { | 
					
						
							| 
									
										
										
										
											2015-08-28 14:31:35 -04:00
										 |  |  | 		return next(); | 
					
						
							| 
									
										
										
										
											2014-09-25 11:29:53 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-11 04:10:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	var errorText; | 
					
						
							|  |  |  | 	if (req.query.error === 'csrf-invalid') { | 
					
						
							|  |  |  | 		errorText = '[[error:csrf-invalid]]'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 	async.waterfall([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (next) { | 
					
						
							| 
									
										
										
										
											2015-11-28 15:33:17 -07:00
										 |  |  | 			if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') { | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 				user.verifyInvitation(req.query, next); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				next(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (next) { | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 			plugins.fireHook('filter:parse.post', { | 
					
						
							|  |  |  | 				postData: { | 
					
						
							|  |  |  | 					content: meta.config.termsOfUse || '', | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	], function (err, termsOfUse) { | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2014-11-08 14:51:05 -05:00
										 |  |  | 			return next(err); | 
					
						
							| 
									
										
										
										
											2014-05-15 03:06:47 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		var loginStrategies = require('../routes/authentication').getLoginStrategies(); | 
					
						
							|  |  |  | 		var data = { | 
					
						
							|  |  |  | 			'register_window:spansize': loginStrategies.length ? 'col-md-6' : 'col-md-12', | 
					
						
							| 
									
										
										
										
											2017-02-18 01:19:20 -07:00
										 |  |  | 			alternate_logins: !!loginStrategies.length, | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.authentication = loginStrategies; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.minimumUsernameLength = parseInt(meta.config.minimumUsernameLength, 10); | 
					
						
							|  |  |  | 		data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10); | 
					
						
							|  |  |  | 		data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10); | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 		data.minimumPasswordStrength = parseInt(meta.config.minimumPasswordStrength || 0, 10); | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		data.termsOfUse = termsOfUse.postData.content; | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 		data.breadcrumbs = helpers.buildBreadcrumbs([{ | 
					
						
							|  |  |  | 			text: '[[register:register]]', | 
					
						
							|  |  |  | 		}]); | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		data.regFormEntry = []; | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 		data.error = req.flash('error')[0] || errorText; | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		data.title = '[[pages:register]]'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		res.render('register', data); | 
					
						
							| 
									
										
										
										
											2014-05-15 03:06:47 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.registerInterstitial = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:05:40 -04:00
										 |  |  | 	if (!req.session.hasOwnProperty('registration')) { | 
					
						
							|  |  |  | 		return res.redirect(nconf.get('relative_path') + '/register'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 16:42:10 +03:00
										 |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			plugins.fireHook('filter:register.interstitial', { | 
					
						
							|  |  |  | 				userData: req.session.registration, | 
					
						
							|  |  |  | 				interstitials: [], | 
					
						
							|  |  |  | 			}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (data, next) { | 
					
						
							|  |  |  | 			if (!data.interstitials.length) { | 
					
						
							|  |  |  | 				// No interstitials, redirect to home
 | 
					
						
							|  |  |  | 				delete req.session.registration; | 
					
						
							|  |  |  | 				return res.redirect('/'); | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-28 16:42:10 +03:00
										 |  |  | 			var renders = data.interstitials.map(function (interstitial) { | 
					
						
							|  |  |  | 				return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 16:42:10 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			async.parallel(renders, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (sections) { | 
					
						
							|  |  |  | 			var errors = req.flash('error'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:05:40 -04:00
										 |  |  | 			res.render('registerComplete', { | 
					
						
							| 
									
										
										
										
											2016-09-28 20:06:16 +03:00
										 |  |  | 				title: '[[pages:registration-complete]]', | 
					
						
							| 
									
										
										
										
											2016-06-22 16:47:24 -04:00
										 |  |  | 				errors: errors, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				sections: sections, | 
					
						
							| 
									
										
										
										
											2016-06-08 16:05:40 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-02-28 16:42:10 +03:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	], next); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:05:40 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.compose = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 	plugins.fireHook('filter:composer.build', { | 
					
						
							|  |  |  | 		req: req, | 
					
						
							|  |  |  | 		res: res, | 
					
						
							|  |  |  | 		next: next, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		templateData: {}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							| 
									
										
										
										
											2015-07-03 17:21:14 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-06-10 15:56:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 		if (data.templateData.disabled) { | 
					
						
							| 
									
										
										
										
											2016-01-12 12:01:17 -05:00
										 |  |  | 			res.render('', { | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				title: '[[modules:composer.compose]]', | 
					
						
							| 
									
										
										
										
											2016-01-12 12:01:17 -05:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-01-12 12:01:17 -05:00
										 |  |  | 			data.templateData.title = '[[modules:composer.compose]]'; | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 			res.render('compose', data.templateData); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-05-21 16:24:40 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-20 08:51:04 -04:00
										 |  |  | Controllers.composePost = function (req, res) { | 
					
						
							|  |  |  | 	var body = req.body; | 
					
						
							|  |  |  | 	var data = { | 
					
						
							|  |  |  | 		uid: req.uid, | 
					
						
							|  |  |  | 		req: req, | 
					
						
							|  |  |  | 		timestamp: Date.now(), | 
					
						
							|  |  |  | 		content: body.content, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	req.body.noscript = 'true'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!data.content) { | 
					
						
							|  |  |  | 		return helpers.noScriptErrors(req, res, '[[error:invalid-data]]', 400); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (body.tid) { | 
					
						
							|  |  |  | 		data.tid = body.tid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		topics.reply(data, function (err, result) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return helpers.noScriptErrors(req, res, err.message, 400); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			user.updateOnlineUsers(result.uid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			res.redirect(nconf.get('relative_path') + '/post/' + result.pid); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} else if (body.cid) { | 
					
						
							|  |  |  | 		data.cid = body.cid; | 
					
						
							|  |  |  | 		data.title = body.title; | 
					
						
							|  |  |  | 		data.tags = []; | 
					
						
							|  |  |  | 		data.thumb = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		topics.post(data, function (err, result) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return helpers.noScriptErrors(req, res, err.message, 400); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			res.redirect(nconf.get('relative_path') + '/topic/' + result.topicData.slug); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.confirmEmail = function (req, res) { | 
					
						
							| 
									
										
										
										
											2015-02-25 14:10:00 -05:00
										 |  |  | 	user.email.confirm(req.params.code, function (err) { | 
					
						
							|  |  |  | 		res.render('confirm', { | 
					
						
							| 
									
										
										
										
											2016-02-25 23:04:19 -05:00
										 |  |  | 			error: err ? err.message : '', | 
					
						
							|  |  |  | 			title: '[[pages:confirm]]', | 
					
						
							| 
									
										
										
										
											2015-02-25 14:10:00 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											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.robots = function (req, res) { | 
					
						
							|  |  |  | 	res.set('Content-Type', 'text/plain'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-10 14:55:57 -04:00
										 |  |  | 	if (meta.config['robots:txt']) { | 
					
						
							|  |  |  | 		res.send(meta.config['robots:txt']); | 
					
						
							| 
									
										
										
										
											2014-02-27 17:16:06 -05:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:56:23 -07:00
										 |  |  | 		res.send('User-agent: *\n' + | 
					
						
							|  |  |  | 			'Disallow: ' + nconf.get('relative_path') + '/admin/\n' + | 
					
						
							|  |  |  | 			'Sitemap: ' + nconf.get('url') + '/sitemap.xml'); | 
					
						
							| 
									
										
										
										
											2014-02-27 17:16:06 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.manifest = function (req, res) { | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 	var manifest = { | 
					
						
							| 
									
										
										
										
											2016-10-18 15:32:28 +03:00
										 |  |  | 		name: meta.config.title || 'NodeBB', | 
					
						
							|  |  |  | 		start_url: nconf.get('relative_path') + '/', | 
					
						
							|  |  |  | 		display: 'standalone', | 
					
						
							|  |  |  | 		orientation: 'portrait', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		icons: [], | 
					
						
							| 
									
										
										
										
											2016-10-18 15:32:28 +03:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (meta.config['brand:touchIcon']) { | 
					
						
							|  |  |  | 		manifest.icons.push({ | 
					
						
							| 
									
										
										
										
											2017-02-08 11:41:24 -07:00
										 |  |  | 			src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-36.png', | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 			sizes: '36x36', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			density: 0.75, | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 		}, { | 
					
						
							| 
									
										
										
										
											2017-02-08 11:41:24 -07:00
										 |  |  | 			src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-48.png', | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 			sizes: '48x48', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			density: 1.0, | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 		}, { | 
					
						
							| 
									
										
										
										
											2017-02-08 11:41:24 -07:00
										 |  |  | 			src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-72.png', | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 			sizes: '72x72', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			density: 1.5, | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 		}, { | 
					
						
							| 
									
										
										
										
											2017-02-08 11:41:24 -07:00
										 |  |  | 			src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-96.png', | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 			sizes: '96x96', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			density: 2.0, | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 		}, { | 
					
						
							| 
									
										
										
										
											2017-02-08 11:41:24 -07:00
										 |  |  | 			src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-144.png', | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 			sizes: '144x144', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			density: 3.0, | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 		}, { | 
					
						
							| 
									
										
										
										
											2017-02-08 11:41:24 -07:00
										 |  |  | 			src: nconf.get('relative_path') + '/assets/uploads/system/touchicon-192.png', | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 			sizes: '192x192', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			density: 4.0, | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res.status(200).json(manifest); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | Controllers.outgoing = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-09-05 22:12:02 +03:00
										 |  |  | 	var url = req.query.url || ''; | 
					
						
							| 
									
										
										
										
											2017-10-10 11:48:06 -04:00
										 |  |  | 	var allowedProtocols = ['http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp', 'webcal']; | 
					
						
							|  |  |  | 	var parsed = require('url').parse(url); | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 11:48:06 -04:00
										 |  |  | 	if (!url || !allowedProtocols.includes(parsed.protocol.slice(0, -1))) { | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | 		return next(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res.render('outgoing', { | 
					
						
							| 
									
										
										
										
											2016-09-05 22:12:02 +03:00
										 |  |  | 		outgoing: validator.escape(String(url)), | 
					
						
							| 
									
										
										
										
											2016-04-25 21:53:56 +03:00
										 |  |  | 		title: meta.config.title, | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 		breadcrumbs: helpers.buildBreadcrumbs([{ | 
					
						
							|  |  |  | 			text: '[[notifications:outgoing_link]]', | 
					
						
							|  |  |  | 		}]), | 
					
						
							| 
									
										
										
										
											2017-03-02 14:57:33 +03:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-02-28 14:04:21 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | Controllers.termsOfUse = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2014-11-14 12:17:24 -05:00
										 |  |  | 	if (!meta.config.termsOfUse) { | 
					
						
							| 
									
										
										
										
											2015-08-28 14:31:35 -04:00
										 |  |  | 		return next(); | 
					
						
							| 
									
										
										
										
											2014-11-14 12:17:24 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-07 20:57:00 +00:00
										 |  |  | 	res.render('tos', { | 
					
						
							|  |  |  | 		termsOfUse: meta.config.termsOfUse, | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-11-14 12:17:24 -05:00
										 |  |  | }; |