Update mysql_login to moin 1.8.
authorMatthijs Kooijman <matthijs@stdin.nl>
Wed, 19 Nov 2008 23:02:58 +0000 (00:02 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Wed, 19 Nov 2008 23:02:58 +0000 (00:02 +0100)
conf/auth/mysql_login.py
conf/farmconfig.py

index 3c97dce787aba69d73a2a32585662f00757037fa..274abcd76d83397287e5f532a71b6eee560b3b17 100644 (file)
@@ -9,10 +9,13 @@
 import MySQLdb
 import md5
 from MoinMoin import user
+from MoinMoin.auth import BaseAuth, ContinueLogin
 
-class mysql_login:
-
-    def __init__(self, dbhost=None, dbuser=None, dbpass=None, dbname=None, dbport=None, method='mysql', verbose=False):
+class mysql_login(BaseAuth):
+    logout_possible = True
+    login_inputs    = ['username', 'password']
+    
+    def __init__(self, name='mysql', dbhost=None, dbuser=None, dbpass=None, dbname=None, dbport=None, verbose=False):
         """
             Authenticate using credentials from a mysql database
         """
@@ -22,7 +25,7 @@ class mysql_login:
         self.dbpass  = dbpass
         self.dbname  = dbname
         self.dbport  = dbport
-        self.method  = method
+        self.name    = name
     
     def check_login(self, request, username, password):
         """ Checks the given username password combination. Returns the
@@ -85,44 +88,43 @@ class mysql_login:
 
         return conn
 
-    def __call__(self, request, **kw):
+    def login(self, request, user_obj, **kw):
         try:
-            username = kw.get('name')
+            username = kw.get('username')
             password = kw.get('password')
-            login = kw.get('login')
-            user_obj = kw.get('user_obj')
 
-            if self.verbose: request.log("mysql_login: got name=%r login=%r" % (username, login))
-            
-            # Only handle login
-            if not login:
-                return user_obj, True
+            if self.verbose: request.log("mysql_login: Trying to log in, username=%r " % (username))
+           
+            # simply continue if something else already logged in
+            # successfully
+            if user_obj and user_obj.valid:
+                return ContinueLogin(user_obj)
 
-            # Deny empty passwords
-            if not password:
-                return None, False
+            # Deny empty username or passwords
+            if not username or not password:
+                return ContinueLogin(user_obj)
 
             email = self.check_login(request, username, password)
             
             # Login incorrect
             if (not email):
                 if self.verbose: request.log("mysql_login: authentication failed for %s" % (username))
-                return None, True
+                return ContinueLogin(user_obj)
 
             if self.verbose: request.log("mysql_login: authenticated %s (email %s)" % (username, email))
 
-            u = user.User(request, auth_username=username, auth_method=self.method, auth_attribs=('password', 'email', ))
+            u = user.User(request, auth_username=username, auth_method=self.name, auth_attribs=('password', 'email', ))
             u.email = email
             #u.remember_me = 0 # 0 enforces cookie_lifetime config param
             u.create_or_update(True)
 
-            return u, True # moin_session has to set the cookie
+            return ContinueLogin(u)
         except:
             import sys
             import traceback
             info = sys.exc_info()
             request.log("mysql_login: authentication failed due to unexpected exception, traceback follows...")
             request.log(''.join(traceback.format_exception(*info)))
-            return None, False
+            return ContinueLogin(user_obj)
 
 # vim: set sw=4 expandtab sts=4:vim
index b60963c65c88c0b9ce131c6e5544adaa30a2e2a4..57175438df8f444aa4447410d140439fd9bb1718 100644 (file)
@@ -196,14 +196,14 @@ class FarmConfig(DefaultConfig):
     # Authentication
     from auth.mysql_login import mysql_login # This comes from plugin
     from dbsettings import phpbb_dbhost, phpbb_dbuser, phpbb_dbpass, phpbb_dbname
-    from MoinMoin.auth import moin_session
     phpbb = mysql_login(
+        name    = 'phpbb',
         verbose = True,
         dbhost  = phpbb_dbhost,
         dbuser  = phpbb_dbuser,
         dbpass  = phpbb_dbpass,
         dbname  = phpbb_dbname,
     )
-    auth = [phpbb, moin_session]
+    auth = [phpbb]
 
     user_autocreate = True