mysql_login: Use logger instead of request.log.
[matthijs/projects/wipi.git] / conf / auth / mysql_login.py
index 274abcd76d83397287e5f532a71b6eee560b3b17..b34ecf95c33c2b1185b3ae1cbbf2b058bd0aa728 100644 (file)
@@ -10,22 +10,28 @@ import MySQLdb
 import md5
 from MoinMoin import user
 from MoinMoin.auth import BaseAuth, ContinueLogin
+from MoinMoin import log
+logging = log.getLogger(__name__)
 
 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):
+    def __init__(self, name='mysql', dbhost=None, dbuser=None, dbpass=None, dbname=None, dbport=None, hint=None):
         """
             Authenticate using credentials from a mysql database
+
+            The name parameter should be unique among all authentication methods.
+
+            The hint parameter is a snippet of HTML that is displayed below the login form.
         """
-        self.verbose = verbose
         self.dbhost  = dbhost
         self.dbuser  = dbuser
         self.dbpass  = dbpass
         self.dbname  = dbname
         self.dbport  = dbport
         self.name    = name
+        self.hint    = hint
     
     def check_login(self, request, username, password):
         """ Checks the given username password combination. Returns the
@@ -82,8 +88,8 @@ class mysql_login(BaseAuth):
             import sys
             import traceback
             info = sys.exc_info()
-            request.log("mysql_login: authentication failed due to exception connecting to DB, traceback follows...")
-            request.log(''.join(traceback.format_exception(*info)))
+            logging.error("mysql_login: authentication failed due to exception connecting to DB, traceback follows...")
+            logging.error(''.join(traceback.format_exception(*info)))
             return False
 
         return conn
@@ -93,7 +99,7 @@ class mysql_login(BaseAuth):
             username = kw.get('username')
             password = kw.get('password')
 
-            if self.verbose: request.log("mysql_login: Trying to log in, username=%r " % (username))
+            logging.debug("mysql_login: Trying to log in, username=%r " % (username))
            
             # simply continue if something else already logged in
             # successfully
@@ -108,12 +114,12 @@ class mysql_login(BaseAuth):
             
             # Login incorrect
             if (not email):
-                if self.verbose: request.log("mysql_login: authentication failed for %s" % (username))
+                logging.debug("mysql_login: authentication failed for %s" % (username))
                 return ContinueLogin(user_obj)
 
-            if self.verbose: request.log("mysql_login: authenticated %s (email %s)" % (username, email))
+            logging.debug("mysql_login: authenticated %s (email %s)" % (username, email))
 
-            u = user.User(request, auth_username=username, auth_method=self.name, auth_attribs=('password', 'email', ))
+            u = user.User(request, auth_username=username, auth_method=self.name, auth_attribs=('name', 'password', 'email'))
             u.email = email
             #u.remember_me = 0 # 0 enforces cookie_lifetime config param
             u.create_or_update(True)
@@ -123,8 +129,12 @@ class mysql_login(BaseAuth):
             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)))
+            logging.error("mysql_login: authentication failed due to unexpected exception, traceback follows...")
+            logging.error(''.join(traceback.format_exception(*info)))
             return ContinueLogin(user_obj)
 
+    def login_hint(self, request):
+        """ Return a snippet of HTML that is displayed with the login form. """
+        return self.hint
+
 # vim: set sw=4 expandtab sts=4:vim