web/views/authentication.py
branchtls-sprint
changeset 1488 6da89a703c5a
parent 0 b97547f5f1fa
child 1490 6b024694d493
--- a/web/views/authentication.py	Mon Apr 27 10:26:51 2009 +0200
+++ b/web/views/authentication.py	Mon Apr 27 19:01:00 2009 +0200
@@ -51,10 +51,18 @@
         # associate the connection to the current request
         req.set_connection(cnx, user)
         return cnx
-        
+
+    def login_from_email(self, login):
+        session = self.repo.internal_session()
+        rset = session.execute('Any L WHERE U login L, U primary_email M, '
+                               'M address %(login)s', {'login': login})
+        if rset.rowcount == 1:
+            login = rset[0][0]
+        return login
+
     def authenticate(self, req, _login=None, _password=None):
         """authenticate user and return corresponding user object
-        
+
         :raise ExplicitLogin: if authentication is required (no authentication
         info found or wrong user/password)
 
@@ -66,6 +74,8 @@
             login, password = _login, _password
         else:
             login, password = req.get_authorization()
+        if '@' in (login or u''):
+            login = self.login_from_email(login)
         if not login:
             # No session and no login -> try anonymous
             login, password = self.vreg.config.anonymous_user()