From 519b1b7e371496946c330df505d6de3502a3d720 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 14 Nov 2014 13:36:37 -0500 Subject: [PATCH] closes #2377 --- public/language/en_GB/error.json | 4 +++- src/controllers/index.js | 1 + src/routes/authentication.js | 21 ++++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index 53987d73d2..40b685354d 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -85,5 +85,7 @@ "not-enough-reputation-to-downvote": "You do not have enough reputation to downvote this post", "not-enough-reputation-to-flag": "You do not have enough reputation to flag this post", - "reload-failed": "NodeBB encountered a problem while reloading: \"%1\". NodeBB will continue to serve the existing client-side assets, although you should undo what you did just prior to reloading." + "reload-failed": "NodeBB encountered a problem while reloading: \"%1\". NodeBB will continue to serve the existing client-side assets, although you should undo what you did just prior to reloading.", + + "registration-error": "Registration Error" } \ No newline at end of file diff --git a/src/controllers/index.js b/src/controllers/index.js index aaba36dcd6..e92f856bc9 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -179,6 +179,7 @@ Controllers.register = function(req, res, next) { data.minimumPasswordLength = meta.config.minimumPasswordLength; data.termsOfUse = meta.config.termsOfUse; data.regFormEntry = []; + data.error = req.flash('error')[0]; plugins.fireHook('filter:register.build', {req: req, res: res, templateData: data}, function(err, data) { if (err && process.env === 'development') { diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 1216968494..f6fe08d5d5 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -207,14 +207,20 @@ } } - if (!userData.username || userData.username.length < meta.config.minimumUsernameLength) { - return res.redirect(nconf.get('relative_path') + '/register?error=[[error:username-too-short]]'); - } else if (!userData.username || userData.username.length > meta.config.maximumUsernameLength) { - return res.redirect(nconf.get('relative_path') + '/register?error=[[error:username-too-long]]'); - } - var uid; async.waterfall([ + function(next) { + if (!userData.username || userData.username.length < meta.config.minimumUsernameLength) { + return next(new Error('[[error:username-too-short]]')); + } + next(); + }, + function(next) { + if (!userData.username || userData.username.length > meta.config.maximumUsernameLength) { + return next(new Error('[[error:username-too-long')); + } + next(); + }, function(next) { plugins.fireHook('filter:register.check', {req: req, res: res, userData: userData}, next); }, @@ -236,7 +242,8 @@ } ], function(err, data) { if (err) { - return res.redirect(nconf.get('relative_path') + '/register?error=' + err.message); + req.flash('error', err.message); + return res.redirect(nconf.get('relative_path') + '/register'); } res.redirect(nconf.get('relative_path') + (data.referrer ? data.referrer : '/')); });