add ability to login with a primary email address - no tests for now are unittest_application.py are now broken tls-sprint
authorFlorent <florent@secondweb.fr>
Mon, 27 Apr 2009 19:01:00 +0200
branchtls-sprint
changeset 1488 6da89a703c5a
parent 1487 7ea2d806de76
child 1489 08acef58ad08
add ability to login with a primary email address - no tests for now are unittest_application.py are now broken
web/views/authentication.py
--- 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()