changeset 5691:b24e015a4174

auth: allow web login with email addresses Let users log in using their email addresses instead of their user names. This only applies to the web login, not git+http or hg+http protocols.
author Andrew Shadura <andrew@shadura.me>
date Sat, 30 Jan 2016 16:37:43 +0100
parents 2c3941817a8e
children 52356a58c1f6
files kallithea/controllers/login.py kallithea/model/validators.py kallithea/tests/functional/test_login.py
diffstat 3 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/login.py	Sat Jan 30 16:36:26 2016 +0100
+++ b/kallithea/controllers/login.py	Sat Jan 30 16:37:43 2016 +0100
@@ -91,7 +91,7 @@
                 c.form_result = login_form.to_python(dict(request.POST))
                 # form checks for username/password, now we're authenticated
                 username = c.form_result['username']
-                user = User.get_by_username(username, case_insensitive=True)
+                user = User.get_by_username_or_email(username, case_insensitive=True)
             except formencode.Invalid as errors:
                 defaults = errors.value
                 # remove password from filling in form again
--- a/kallithea/model/validators.py	Sat Jan 30 16:36:26 2016 +0100
+++ b/kallithea/model/validators.py	Sat Jan 30 16:37:43 2016 +0100
@@ -313,7 +313,7 @@
             # authenticate returns unused dict but has called
             # plugin._authenticate which has create_or_update'ed the username user in db
             if auth_modules.authenticate(username, password) is None:
-                user = User.get_by_username(username)
+                user = User.get_by_username_or_email(username)
                 if user and not user.active:
                     log.warning('user %s is disabled', username)
                     msg = M(self, 'invalid_auth', state)
--- a/kallithea/tests/functional/test_login.py	Sat Jan 30 16:36:26 2016 +0100
+++ b/kallithea/tests/functional/test_login.py	Sat Jan 30 16:37:43 2016 +0100
@@ -50,6 +50,17 @@
         response = response.follow()
         response.mustcontain('/%s' % HG_REPO)
 
+    def test_login_regular_email_ok(self):
+        response = self.app.post(url(controller='login', action='index'),
+                                 {'username': TEST_USER_REGULAR_EMAIL,
+                                  'password': TEST_USER_REGULAR_PASS})
+
+        self.assertEqual(response.status, '302 Found')
+        self.assert_authenticated_user(response, TEST_USER_REGULAR_LOGIN)
+
+        response = response.follow()
+        response.mustcontain('/%s' % HG_REPO)
+
     def test_login_ok_came_from(self):
         test_came_from = '/_admin/users'
         response = self.app.post(url(controller='login', action='index',