From fd78eb6d5786b068bd7a7cb674f9f3ca84ac37c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 5 Dec 2017 13:18:37 -0500 Subject: [PATCH] closes #5533 --- public/src/app.js | 17 +++++++++++++--- src/controllers/authentication.js | 32 ++++++++++++++++--------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 421cf71943..f3d27e7ef0 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -9,7 +9,9 @@ app.widgets = {}; app.cacheBuster = null; (function () { - var showWelcomeMessage = !!utils.params().loggedin; + var params = utils.params(); + var showWelcomeMessage = !!params.loggedin; + var registerMessage = params.register; require(['benchpress'], function (Benchpress) { Benchpress.setGlobal('config', config); @@ -286,9 +288,12 @@ app.cacheBuster = null; title: '[[global:welcome_back]] ' + app.user.username + '!', message: '[[global:you_have_successfully_logged_in]]', }, + register: { + format: 'modal', + }, }; - function showAlert(type) { + function showAlert(type, message) { switch (messages[type].format) { case 'alert': app.alert({ @@ -301,7 +306,7 @@ app.cacheBuster = null; case 'modal': require(['translator'], function (translator) { - translator.translate(messages[type].message, function (translated) { + translator.translate(message || messages[type].message, function (translated) { bootbox.alert({ title: messages[type].title, message: translated, @@ -318,6 +323,12 @@ app.cacheBuster = null; showAlert('login'); }); } + if (registerMessage) { + $(document).ready(function () { + showAlert('register', decodeURIComponent(registerMessage)); + registerMessage = false; + }); + } }; app.openChat = function (roomId, uid) { diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index 8c9666e4f4..c6b418ff9b 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -57,18 +57,7 @@ authenticationController.register = function (req, res) { user.isPasswordValid(userData.password, next); }, function (next) { - user.shouldQueueUser(req.ip, next); - }, - function (queue, next) { - res.locals.processLogin = true; // set it to false in plugin if you wish to just register only - plugins.fireHook('filter:register.check', { req: req, res: res, userData: userData, queue: queue }, next); - }, - function (data, next) { - if (data.queue) { - addToApprovalQueue(req, userData, next); - } else { - registerAndLoginUser(req, res, userData, next); - } + registerAndLoginUser(req, res, userData, next); }, ], function (err, data) { if (err) { @@ -108,7 +97,18 @@ function registerAndLoginUser(req, res, userData, callback) { return res.json({ referrer: nconf.get('relative_path') + '/register/complete' }); }, function (next) { - user.create(userData, next); + user.shouldQueueUser(req.ip, next); + }, + function (queue, next) { + res.locals.processLogin = true; // set it to false in plugin if you wish to just register only + plugins.fireHook('filter:register.check', { req: req, res: res, userData: userData, queue: queue }, next); + }, + function (data, next) { + if (data.queue) { + addToApprovalQueue(req, userData, callback); + } else { + user.create(userData, next); + } }, function (_uid, next) { uid = _uid; @@ -155,9 +155,11 @@ authenticationController.registerComplete = function (req, res, next) { return memo; }, []); - var done = function () { + var done = function (err, data) { delete req.session.registration; - + if (!err && data && data.message) { + return res.redirect(nconf.get('relative_path') + '/?register=' + encodeURIComponent(data.message)); + } if (req.session.returnTo) { res.redirect(req.session.returnTo); } else {