[PATCH v2] auth: let users log in using their email address

Andrew Shadura andrew at shadura.me
Sat May 16 09:49:49 EDT 2015


# HG changeset patch
# User Andrew Shadura <andrew at shadura.me>
# Date 1431709586 -7200
#      Fri May 15 19:06:26 2015 +0200
# Node ID 93de511e84fe940786acf468789a77daed83a461
# Parent  95bffe63997d40bfab5ae6b8d1a54859d6275471
auth: let users log in using their email address

diff --git a/kallithea/controllers/login.py b/kallithea/controllers/login.py
--- a/kallithea/controllers/login.py
+++ b/kallithea/controllers/login.py
@@ -121,9 +121,15 @@ class LoginController(BaseController):
                 session.invalidate()
                 c.form_result = login_form.to_python(dict(request.POST))
                 # form checks for username/password, now we're authenticated
+
+                username = c.form_result['username']
+                if '@' in username:
+                    username = User.get_by_email(username).username
+                remember = c.form_result['remember']
+
                 headers = self._store_user_in_session(
-                                        username=c.form_result['username'],
-                                        remember=c.form_result['remember'])
+                                        username=username,
+                                        remember=remember)
                 raise HTTPFound(location=c.came_from, headers=headers)
             except formencode.Invalid, errors:
                 defaults = errors.value
diff --git a/kallithea/model/validators.py b/kallithea/model/validators.py
--- a/kallithea/model/validators.py
+++ b/kallithea/model/validators.py
@@ -316,6 +316,11 @@ def ValidAuth():
             password = value['password']
             username = value['username']
 
+            if '@' in username:
+                user = User.get_by_email(username)
+                if user:
+                    username = user.username
+
             if not auth_modules.authenticate(username, password):
                 user = User.get_by_username(username)
                 if user and not user.active:


More information about the kallithea-general mailing list