Changeset 3538
- Timestamp:
- 04/21/08 01:21:49 (7 months ago)
- Files:
-
- phpbbauthplugin/0.11/phpbbauth/main.py (modified) (4 diffs)
- phpbbauthplugin/0.11/setup.cfg (modified) (1 diff)
- phpbbauthplugin/0.11/setup.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
phpbbauthplugin/0.11/phpbbauth/main.py
r3530 r3538 25 25 from trac.core import Component, implements 26 26 from trac.db.api import DatabaseManager 27 from trac.config import Option 27 28 from acct_mgr.api import IPasswordStore 28 29 … … 43 44 """ Deprecated """ 44 45 45 def get_users(self ):46 def get_users(self, populate_session=True): 46 47 """ Pull list of current users from PhpBB3 """ 47 48 cnx = PhpDatabaseManager(self.env).get_connection() 48 49 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] 50 54 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] 52 58 53 59 def has_user(self, user): … … 57 63 cur.execute('SELECT username FROM phpbb_users WHERE user_type <> 2' 58 64 ' AND username = %s', (user,)) 65 result = [u for u in cur] 59 66 cnx.close() 60 return curand True or False67 return result and True or False 61 68 62 69 # def set_password(self, user, password): … … 85 92 def _get_pwhash(self, user): 86 93 """ 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() 87 133 88 134 phpbbauthplugin/0.11/setup.cfg
r3530 r3538 1 1 [egg_info] 2 tag_build = dev3 tag_svn_revision = true2 ;tag_build = dev 3 ;tag_svn_revision = true 4 4 phpbbauthplugin/0.11/setup.py
r3530 r3538 11 11 description = 'Authentication against PhpBB3. Requires Account Manager', 12 12 13 license = 'MIT' 13 license = 'MIT', 14 14 zip_safe=True, 15 15 packages=['phpbbauth'], … … 20 20 entry_points = { 21 21 'trac.plugins': [ 22 'phpbbauth.main = main.main',22 'phpbbauth.main = phpbbauth.main', 23 23 ] 24 24 },
