From: Matthijs Kooijman Date: Wed, 19 Nov 2008 23:02:58 +0000 (+0100) Subject: Update mysql_login to moin 1.8. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=e5f40cdde2e9c100a7c1997cc5adb1bf96199483;p=matthijs%2Fprojects%2Fwipi.git Update mysql_login to moin 1.8. --- diff --git a/conf/auth/mysql_login.py b/conf/auth/mysql_login.py index 3c97dce..274abcd 100644 --- a/conf/auth/mysql_login.py +++ b/conf/auth/mysql_login.py @@ -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 diff --git a/conf/farmconfig.py b/conf/farmconfig.py index b60963c..5717543 100644 --- a/conf/farmconfig.py +++ b/conf/farmconfig.py @@ -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