From d7d4290099c3c0438110cdd625723acf7b5ec4cc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 26 Jan 2014 13:10:39 -0500 Subject: [PATCH 1/4] resolved #879 --- src/plugins.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins.js b/src/plugins.js index 375616c414..9b7257204b 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -202,6 +202,10 @@ var fs = require('fs'), } else return; }; + Plugins.hasListeners = function(hook, callback) { + return Plugins.loadedHooks[hook].length > 0; + }; + Plugins.fireHook = function(hook, args, callback) { hookList = Plugins.loadedHooks[hook]; From 96b2a1529038b4818d5c76f3c0211fcca6e0777b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 26 Jan 2014 13:21:23 -0500 Subject: [PATCH 2/4] user registration now no longer sends a welcome email if no emailers are present --- src/plugins.js | 4 ++-- src/user.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins.js b/src/plugins.js index 9b7257204b..5f1bd0d4e2 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -202,8 +202,8 @@ var fs = require('fs'), } else return; }; - Plugins.hasListeners = function(hook, callback) { - return Plugins.loadedHooks[hook].length > 0; + Plugins.hasListeners = function(hook) { + return (Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0); }; Plugins.fireHook = function(hook, args, callback) { diff --git a/src/user.js b/src/user.js index 4728f4b824..4ddfa25f16 100644 --- a/src/user.js +++ b/src/user.js @@ -886,6 +886,10 @@ var bcrypt = require('bcrypt'), User.email = { verify: function(uid, email) { + if (!plugins.hasListeners('action:email.send')) { + return; + } + var confirm_code = utils.generateUUID(), confirm_link = nconf.get('url') + '/confirm/' + confirm_code; From 22354227be7f710ebf0b93d303f72b717ad980c9 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 26 Jan 2014 15:59:22 -0500 Subject: [PATCH 3/4] hiding "Forgot Password" link using Plugins.hasListeners, instead of derpy config settings bool --- public/src/forum/login.js | 6 ------ public/templates/login.tpl | 5 ++++- src/routes/api.js | 11 ++++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/public/src/forum/login.js b/public/src/forum/login.js index 9dca615a75..563db9d64e 100644 --- a/public/src/forum/login.js +++ b/public/src/forum/login.js @@ -52,12 +52,6 @@ define(function() { }); document.querySelector('#content input').focus(); - - if(!config.emailSetup) - $('#reset-link').addClass('hide'); - else - $('#reset-link').removeClass('hide'); - }; return Login; diff --git a/public/templates/login.tpl b/public/templates/login.tpl index 1557a6c2e3..8f7807421d 100644 --- a/public/templates/login.tpl +++ b/public/templates/login.tpl @@ -41,7 +41,10 @@

-   [[login:forgot_password]] + + +   [[login:forgot_password]] +
diff --git a/src/routes/api.js b/src/routes/api.js index 6dbb0080f7..08d4107f74 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -11,10 +11,11 @@ var path = require('path'), posts = require('../posts'), categories = require('../categories'), categoryTools = require('../categoryTools') + meta = require('../meta'), + Plugins = require('../plugins'), utils = require('../../public/src/utils'), translator = require('../../public/src/translator'), - pkg = require('../../package.json'), - meta = require('../meta'); + pkg = require('../../package.json'); (function (Api) { @@ -46,7 +47,6 @@ var path = require('path'), config.topicsPerPage = meta.config.topicsPerPage || 20; config.postsPerPage = meta.config.postsPerPage || 20; config.maximumFileSize = meta.config.maximumFileSize; - config.emailSetup = !!meta.config['email:from']; config.defaultLang = meta.config.defaultLang || 'en'; res.json(200, config); @@ -116,7 +116,8 @@ var path = require('path'), app.get('/login', function (req, res) { var data = {}, login_strategies = auth.get_login_strategies(), - num_strategies = login_strategies.length; + num_strategies = login_strategies.length, + emailersPresent = Plugins.hasListeners('action:email.send'); if (num_strategies == 0) { data = { @@ -131,8 +132,8 @@ var path = require('path'), } data.authentication = login_strategies; - data.token = res.locals.csrf_token; + data.showResetLink = emailersPresent; res.json(data); }); From 0c71707fb5bb52196a367c440da8ee930d80e051 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 26 Jan 2014 16:22:50 -0500 Subject: [PATCH 4/4] fixed #877 --- public/src/forum/topic.js | 6 +++--- src/socket.io/topics.js | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 518ea3d64b..b241c9cc5e 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -1097,7 +1097,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { var insertAfter = findInsertionPoint(); - parseAndTranslatePosts(data.posts, function(translatedHTML) { + parseAndTranslatePosts(data, function(translatedHTML) { var translated = $(translatedHTML); if(!infiniteLoaded) { @@ -1112,8 +1112,8 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { }); } - function parseAndTranslatePosts(posts, callback) { - var html = templates.prepare(templates['topic'].blocks['posts']).parse({posts: posts}); + function parseAndTranslatePosts(data, callback) { + var html = templates.prepare(templates['topic'].blocks['posts']).parse(data); var regexp = new RegExp("([\\s\\S]*?)", 'g'); html = html.replace(regexp, ''); diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 6ea39afbc9..b81b484610 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -1,6 +1,9 @@ var topics = require('../topics'), threadTools = require('../threadTools'), index = require('./index'), + + async = require('async'), + SocketTopics = {}; SocketTopics.post = function(socket, data, callback) { @@ -236,12 +239,15 @@ SocketTopics.loadMore = function(socket, data, callback) { var start = data.after, end = start + postsPerPage - 1; - topics.getTopicPosts(data.tid, start, end, socket.uid, function(err, posts) { - if(err) { - return callback(err); + async.parallel({ + posts: function(next) { + topics.getTopicPosts(data.tid, start, end, socket.uid, next); + }, + privileges: function(next) { + threadTools.privileges(data.tid, socket.uid, next); } - - callback(err, {posts: posts}); + }, function(err, results) { + callback(err, results); }); };