From da305210e2ef487e853f2db2df9b97669cfce380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 19 Feb 2015 13:24:06 -0500 Subject: [PATCH] closes #2618 --- public/language/en_GB/error.json | 4 +++- public/language/en_GB/login.json | 4 +++- src/controllers/index.js | 1 + src/routes/authentication.js | 11 ++++++++--- src/views/admin/settings/user.tpl | 9 +++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index 8c2fadce8d..812ae03a17 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -96,5 +96,7 @@ "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", - "parse-error": "Something went wrong while parsing server response" + "parse-error": "Something went wrong while parsing server response", + "wrong-login-type-email": "Please use your email to login", + "wrong-login-type-username": "Please use your username to login" } \ No newline at end of file diff --git a/public/language/en_GB/login.json b/public/language/en_GB/login.json index fe23e7d441..02abac6371 100644 --- a/public/language/en_GB/login.json +++ b/public/language/en_GB/login.json @@ -1,5 +1,7 @@ { - "username": "Username / Email", + "username-email": "Username / Email", + "username": "Username", + "email": "Email", "remember_me": "Remember Me?", "forgot_password": "Forgot Password?", "alternative_logins": "Alternative Logins", diff --git a/src/controllers/index.js b/src/controllers/index.js index c8511c7c61..8a43da5c9f 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -70,6 +70,7 @@ Controllers.login = function(req, res, next) { data.showResetLink = emailersPresent; data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1; data.allowRegistration = parseInt(meta.config.allowRegistration, 10) === 1; + data.allowLoginWith = '[[login:' + (meta.config.allowLoginWith || 'username-email') + ']]'; data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:login]]'}]); data.error = req.flash('error')[0]; diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 649d6d87dd..5b8a3ffe5f 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -4,11 +4,12 @@ var passport = require('passport'), passportLocal = require('passport-local').Strategy, nconf = require('nconf'), - Password = require('../password'), winston = require('winston'), async = require('async'), + validator = require('validator'), express = require('express'), + Password = require('../password'), meta = require('../meta'), user = require('../user'), plugins = require('../plugins'), @@ -131,7 +132,9 @@ req.session.returnTo = req.body.returnTo; } - if (req.body.username && utils.isEmailValid(req.body.username)) { + var loginWith = meta.config.allowLoginWith || 'username-email'; + + if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.indexOf('email') !== -1) { user.getUsernameByEmail(req.body.username, function(err, username) { if (err) { return next(err); @@ -139,8 +142,10 @@ req.body.username = username ? username : req.body.username; continueLogin(req, res, next); }); - } else { + } else if (loginWith.indexOf('username') !== -1 && !validator.isEmail(req.body.username)) { continueLogin(req, res, next); + } else { + res.status(500).send('[[error:wrong-login-type-' + loginWith + ']]'); } } diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index b44884ae81..cc11b93727 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -29,6 +29,15 @@ Require Email Confirmation + +
+ + +