From 514c12aa68c067d9c992ff2023f2b9d8cf13eea1 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 29 Jul 2016 16:26:27 +0300 Subject: [PATCH] closes #4885 --- public/language/en_GB/error.json | 1 + public/src/app.js | 54 +++++++++++++++++--------------- src/middleware/header.js | 8 +++++ src/user/email.js | 5 +-- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index 76b2bef1a8..fa73ccfa8a 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -25,6 +25,7 @@ "email-taken": "Email taken", "email-not-confirmed": "Your email has not been confirmed yet, please click here to confirm your email.", "email-not-confirmed-chat": "You are unable to chat until your email is confirmed, please click here to confirm your email.", + "email-not-confirmed-email-sent": "Your email has not been confirmed yet, please check your inbox for the confirmation email.", "no-email-to-confirm": "This forum requires email confirmation, please click here to enter an email", "email-confirm-failed": "We could not confirm your email, please try again later.", "confirm-email-already-sent": "Confirmation email already sent, please wait %1 minute(s) to send another one.", diff --git a/public/src/app.js b/public/src/app.js index 8875bd2d64..e9b52ef0bf 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -473,33 +473,35 @@ app.cacheBuster = null; if (!config.requireEmailConfirmation || !app.user.uid) { return; } + var msg = { + alert_id: 'email_confirm', + type: 'warning', + timeout: 0 + }; + if (!app.user.email) { - app.alert({ - alert_id: 'email_confirm', - message: '[[error:no-email-to-confirm]]', - type: 'warning', - timeout: 0, - clickfn: function() { - app.removeAlert('email_confirm'); - ajaxify.go('user/' + app.user.userslug + '/edit'); - } - }); - } else if (!app.user['email:confirmed']) { - app.alert({ - alert_id: 'email_confirm', - message: err ? err.message : '[[error:email-not-confirmed]]', - type: 'warning', - timeout: 0, - clickfn: function() { - app.removeAlert('email_confirm'); - socket.emit('user.emailConfirm', {}, function(err) { - if (err) { - return app.alertError(err.message); - } - app.alertSuccess('[[notifications:email-confirm-sent]]'); - }); - } - }); + msg.message = '[[error:no-email-to-confirm]]'; + msg.clickfn = function() { + app.removeAlert('email_confirm'); + ajaxify.go('user/' + app.user.userslug + '/edit'); + }; + app.alert(msg); + } else if (!app.user['email:confirmed'] && !app.user.isEmailConfirmSent) { + msg.message = err ? err.message : '[[error:email-not-confirmed]]'; + msg.clickfn = function() { + app.removeAlert('email_confirm'); + socket.emit('user.emailConfirm', {}, function(err) { + if (err) { + return app.alertError(err.message); + } + app.alertSuccess('[[notifications:email-confirm-sent]]'); + }); + }; + + app.alert(msg); + } else if (!app.user['email:confirmed'] && app.user.isEmailConfirmSent) { + msg.message = '[[error:email-not-confirmed-email-sent]]'; + app.alert(msg); } }; diff --git a/src/middleware/header.js b/src/middleware/header.js index ef73610b92..4f25a55ca5 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -3,6 +3,7 @@ var async = require('async'); var nconf = require('nconf'); +var db = require('../database'); var user = require('../user'); var meta = require('../meta'); var plugins = require('../plugins'); @@ -94,6 +95,12 @@ module.exports = function(app, middleware) { next(null, userData); } }, + isEmailConfirmSent: function(next) { + if (!meta.config.requireEmailConfirmation || !req.uid) { + return next(null, false); + } + db.get('uid:' + req.uid + ':confirm:email:sent', next); + }, navigation: async.apply(navigation.get), tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags) }, function(err, results) { @@ -110,6 +117,7 @@ module.exports = function(app, middleware) { results.user.isGlobalMod = results.isGlobalMod; results.user.uid = parseInt(results.user.uid, 10); results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1; + results.user.isEmailConfirmSent = !!results.isEmailConfirmSent; if (parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && res.locals.config.bootswatchSkin !== 'default') { templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + res.locals.config.bootswatchSkin + '/bootstrap.min.css'; diff --git a/src/user/email.js b/src/user/email.js index 4b98cc72aa..902d2ead73 100644 --- a/src/user/email.js +++ b/src/user/email.js @@ -28,8 +28,8 @@ var emailer = require('../emailer'); UserEmail.sendValidationEmail = function(uid, email, callback) { callback = callback || function() {}; - var confirm_code = utils.generateUUID(), - confirm_link = nconf.get('url') + '/confirm/' + confirm_code; + var confirm_code = utils.generateUUID(); + var confirm_link = nconf.get('url') + '/confirm/' + confirm_code; var emailInterval = meta.config.hasOwnProperty('emailConfirmInterval') ? parseInt(meta.config.emailConfirmInterval, 10) : 10; @@ -97,6 +97,7 @@ var emailer = require('../emailer'); async.series([ async.apply(user.setUserField, confirmObj.uid, 'email:confirmed', 1), async.apply(db.delete, 'confirm:' + code), + async.apply(db.delete, 'uid:' + confirmObj.uid + ':confirm:email:sent'), function(next) { db.sortedSetRemove('users:notvalidated', confirmObj.uid, next); }