Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r a440253ac1d6 authopenid/authopenid.py
- --- a/authopenid/authopenid.py Sat Apr 16 23:22:04 2011 +0300
- +++ b/authopenid/authopenid.py Mon May 02 16:47:23 2011 +0200
- @@ -170,7 +170,7 @@
- return generated_list
- def __init__(self):
- - db = self.env.get_db_cnx()
- + #db = self.env.get_db_cnx()
- oidutil.log = OpenIdLogger(self.env)
- self.env.log.debug("Compiling white-list")
- self.re_white_list = self.generate_re_list(self.white_list)
- @@ -201,9 +201,9 @@
- # IEnvironmentSetupParticipant methods
- def environment_created(self):
- - db = self.env.get_db_cnx()
- - self._initStore(db)
- - db.commit()
- + @self.env.with_transaction()
- + def do_initStore(db):
- + self._initStore(db)
- def environment_needs_upgrade(self, db):
- c = db.cursor()
- @@ -349,7 +349,7 @@
- immediate = 'immediate' in req.args
- - db = self.env.get_db_cnx()
- + db = self.env.get_read_db()
- oidconsumer, session = self._get_consumer(req, db)
- try:
- self.env.log.debug('beginning OpenID authentication.')
- @@ -449,7 +449,7 @@
- def _do_process(self, req):
- """Handle the redirect from the OpenID server.
- """
- - db = self.env.get_db_cnx()
- + db = self.env.get_read_db()
- oidconsumer, session = self._get_consumer(req, db)
- # Ask the library to check the response that the server sent
- @@ -587,12 +587,12 @@
- req.authname = remote_user
- - db = self.env.get_db_cnx()
- - cursor = db.cursor()
- - cursor.execute("INSERT INTO auth_cookie (cookie,name,ipnr,time) "
- - "VALUES (%s, %s, %s, %s)", (cookie, remote_user,
- - self._get_masked_address(req.remote_addr), int(time.time())))
- - db.commit()
- + @self.env.with_transaction()
- + def insert_auth_cookie(db):
- + cursor = db.cursor()
- + cursor.execute("INSERT INTO auth_cookie (cookie,name,ipnr,time) "
- + "VALUES (%s, %s, %s, %s)", (cookie, remote_user,
- + self._get_masked_address(req.remote_addr), int(time.time())))
- req.redirect(req.session.get('oid.referer') or self.env.abs_href())
- else:
- @@ -653,11 +653,11 @@
- # While deleting this cookie we also take the opportunity to delete
- # cookies older than trac_auth_expires
- - db = self.env.get_db_cnx()
- - cursor = db.cursor()
- - cursor.execute("DELETE FROM auth_cookie WHERE name=%s OR time < %s",
- - (req.authname, int(time.time()) - self.trac_auth_expires))
- - db.commit()
- + @self.env.with_transaction()
- + def delete_auth_cookie(db):
- + cursor = db.cursor()
- + cursor.execute("DELETE FROM auth_cookie WHERE name=%s OR time < %s",
- + (req.authname, int(time.time()) - self.trac_auth_expires))
- self._expire_cookie(req)
- custom_redirect = self.config['metanav'].get('logout.redirect')
- if custom_redirect:
- @@ -676,7 +676,7 @@
- self.env.log.debug('trac_auth cookie expired.')
- def _get_name_for_cookie(self, req, cookie):
- - db = self.env.get_db_cnx()
- + db = self.env.get_read_db()
- cursor = db.cursor()
- if self.check_ip:
- cursor.execute("SELECT name FROM auth_cookie "
- @@ -691,9 +691,11 @@
- # be generated by different trac authentication mechanism.
- return None
- elif self.timeout:
- - cursor.execute("UPDATE auth_cookie SET time=%s "
- - "WHERE cookie=%s AND name=%s",
- - (int(time.time()), cookie.value, row[0]))
- + @self.env.with_transaction()
- + def update_auth_cookie(db):
- + cursor.execute("UPDATE auth_cookie SET time=%s "
- + "WHERE cookie=%s AND name=%s",
- + (int(time.time()), cookie.value, row[0]))
- req.outcookie['trac_auth'] = cookie.value
- req.outcookie['trac_auth']['path'] = req.href()
- req.outcookie['trac_auth']['expires'] = self.trac_auth_expires
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement