Changeset 3538

Show
Ignore:
Timestamp:
04/21/08 01:21:49 (7 months ago)
Author:
pacopablo
Message:

Released version 0.1 of phpBB Auth Plugin.

  • Use users and passwords from phpBB for Trac authentication
  • Initialize user sessions and email addresses based on phpBB
    data when visiting the "Users" page of Web Admin
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • phpbbauthplugin/0.11/phpbbauth/main.py

    r3530 r3538  
    2525from trac.core import Component, implements 
    2626from trac.db.api import DatabaseManager 
     27from trac.config import Option 
    2728from acct_mgr.api import IPasswordStore 
    2829 
     
    4344        """ Deprecated """ 
    4445 
    45     def get_users(self): 
     46    def get_users(self, populate_session=True): 
    4647        """ Pull list of current users from PhpBB3 """ 
    4748        cnx = PhpDatabaseManager(self.env).get_connection() 
    4849        cur = cnx.cursor() 
    49         cur.execute('SELECT username FROM phpbb_users WHERE user_type <> 2') 
     50        cur.execute('SELECT username, user_email, user_lastvisit' 
     51                    '  FROM phpbb_users ' 
     52                    ' WHERE user_type <> 2') 
     53        userinfo = [u for u in cur] 
    5054        cnx.close() 
    51         return cur and [u for u in cur] or [] 
     55        if populate_session: 
     56            self._populate_user_session(userinfo) 
     57        return [u[0] for u in userinfo] 
    5258 
    5359    def has_user(self, user): 
     
    5763        cur.execute('SELECT username FROM phpbb_users WHERE user_type <> 2' 
    5864                    ' AND username = %s', (user,)) 
     65        result = [u for u in cur] 
    5966        cnx.close() 
    60         return cur and True or False 
     67        return result and True or False 
    6168 
    6269#    def set_password(self, user, password): 
     
    8592    def _get_pwhash(self, user): 
    8693        """ Return the password hash from the database """ 
     94        cnx = PhpDatabaseManager(self.env).get_connection() 
     95        cur = cnx.cursor() 
     96        cur.execute('SELECT user_password' 
     97                    '  FROM phpbb_users' 
     98                    ' WHERE user_type <> 2' 
     99                    '   AND username = %s', (user,)) 
     100        result = cur.fetchone() 
     101        pwhash = result and result[0] or None 
     102        cnx.close() 
     103        return pwhash 
     104 
     105    def _populate_user_session(self, userinfo): 
     106        """ Create user session entries and populate email and last visit """ 
     107 
     108        # Kind of ugly.  First try to insert a new session record.  If it 
     109        # fails, don't worry, means it's already there.  Second, insert the 
     110        # email address session attribute.  If it fails, don't worry, it's 
     111        # already there. 
     112        cnx = self.env.get_db_cnx() 
     113        for uname, email, lastvisit in userinfo: 
     114            try: 
     115                cur = cnx.cursor() 
     116                cur.execute('INSERT INTO session (sid, authenticated, ' 
     117                            'last_visit) VALUES (%s, 1, %s)', 
     118                            (uname, lastvisit)) 
     119                cnx.commit() 
     120            except: 
     121                cnx.rollback() 
     122            try: 
     123                cur = cnx.cursor() 
     124                cur.execute("INSERT INTO session_attribute" 
     125                            "    (sid, authenticated, name, value)" 
     126                            " VALUES (%s, 1, 'email', %s)", 
     127                            (uname, email)) 
     128                cnx.commit() 
     129            except: 
     130                cnx.rollback() 
     131            continue 
     132        cnx.close() 
    87133          
    88134 
  • phpbbauthplugin/0.11/setup.cfg

    r3530 r3538  
    11[egg_info] 
    2 tag_build = dev 
    3 tag_svn_revision = true 
     2;tag_build = dev 
     3;tag_svn_revision = true 
    44 
  • phpbbauthplugin/0.11/setup.py

    r3530 r3538  
    1111    description = 'Authentication against PhpBB3.  Requires Account Manager', 
    1212 
    13     license = 'MIT' 
     13    license = 'MIT', 
    1414    zip_safe=True, 
    1515    packages=['phpbbauth'], 
     
    2020    entry_points = { 
    2121        'trac.plugins': [ 
    22             'phpbbauth.main = main.main', 
     22            'phpbbauth.main = phpbbauth.main', 
    2323        ] 
    2424    },