Advertisement
Guest User

authopenid-for-trac-0.12.patch

a guest
May 2nd, 2011
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.33 KB | None | 0 0
  1. diff -r a440253ac1d6 authopenid/authopenid.py
  2. --- a/authopenid/authopenid.py  Sat Apr 16 23:22:04 2011 +0300
  3. +++ b/authopenid/authopenid.py  Mon May 02 16:47:23 2011 +0200
  4. @@ -170,7 +170,7 @@
  5.          return generated_list
  6.  
  7.      def __init__(self):
  8. -        db = self.env.get_db_cnx()
  9. +        #db = self.env.get_db_cnx()
  10.          oidutil.log = OpenIdLogger(self.env)
  11.          self.env.log.debug("Compiling white-list")
  12.          self.re_white_list = self.generate_re_list(self.white_list)
  13. @@ -201,9 +201,9 @@
  14.      # IEnvironmentSetupParticipant methods
  15.  
  16.      def environment_created(self):
  17. -        db = self.env.get_db_cnx()
  18. -        self._initStore(db)
  19. -        db.commit()
  20. +   @self.env.with_transaction()
  21. +   def do_initStore(db):
  22. +       self._initStore(db)
  23.  
  24.      def environment_needs_upgrade(self, db):
  25.          c = db.cursor()
  26. @@ -349,7 +349,7 @@
  27.  
  28.          immediate = 'immediate' in req.args
  29.  
  30. -        db = self.env.get_db_cnx()
  31. +        db = self.env.get_read_db()
  32.          oidconsumer, session = self._get_consumer(req, db)
  33.          try:
  34.              self.env.log.debug('beginning OpenID authentication.')
  35. @@ -449,7 +449,7 @@
  36.      def _do_process(self, req):
  37.          """Handle the redirect from the OpenID server.
  38.         """
  39. -        db = self.env.get_db_cnx()
  40. +        db = self.env.get_read_db()
  41.          oidconsumer, session = self._get_consumer(req, db)
  42.  
  43.          # Ask the library to check the response that the server sent
  44. @@ -587,12 +587,12 @@
  45.  
  46.                  req.authname = remote_user
  47.  
  48. -                db = self.env.get_db_cnx()
  49. -                cursor = db.cursor()
  50. -                cursor.execute("INSERT INTO auth_cookie (cookie,name,ipnr,time) "
  51. -                               "VALUES (%s, %s, %s, %s)", (cookie, remote_user,
  52. -                               self._get_masked_address(req.remote_addr), int(time.time())))
  53. -                db.commit()
  54. +                @self.env.with_transaction()
  55. +                def insert_auth_cookie(db):
  56. +                    cursor = db.cursor()
  57. +                    cursor.execute("INSERT INTO auth_cookie (cookie,name,ipnr,time) "
  58. +                                   "VALUES (%s, %s, %s, %s)", (cookie, remote_user,
  59. +                                   self._get_masked_address(req.remote_addr), int(time.time())))
  60.  
  61.                  req.redirect(req.session.get('oid.referer') or self.env.abs_href())
  62.              else:
  63. @@ -653,11 +653,11 @@
  64.  
  65.          # While deleting this cookie we also take the opportunity to delete
  66.          # cookies older than trac_auth_expires
  67. -        db = self.env.get_db_cnx()
  68. -        cursor = db.cursor()
  69. -        cursor.execute("DELETE FROM auth_cookie WHERE name=%s OR time < %s",
  70. -                       (req.authname, int(time.time()) - self.trac_auth_expires))
  71. -        db.commit()
  72. +        @self.env.with_transaction()
  73. +        def delete_auth_cookie(db):
  74. +            cursor = db.cursor()
  75. +            cursor.execute("DELETE FROM auth_cookie WHERE name=%s OR time < %s",
  76. +                           (req.authname, int(time.time()) - self.trac_auth_expires))
  77.          self._expire_cookie(req)
  78.          custom_redirect = self.config['metanav'].get('logout.redirect')
  79.          if custom_redirect:
  80. @@ -676,7 +676,7 @@
  81.          self.env.log.debug('trac_auth cookie expired.')
  82.  
  83.      def _get_name_for_cookie(self, req, cookie):
  84. -        db = self.env.get_db_cnx()
  85. +        db = self.env.get_read_db()
  86.          cursor = db.cursor()
  87.          if self.check_ip:
  88.              cursor.execute("SELECT name FROM auth_cookie "
  89. @@ -691,9 +691,11 @@
  90.              # be generated by different trac authentication mechanism.
  91.              return None
  92.          elif self.timeout:
  93. -            cursor.execute("UPDATE auth_cookie SET time=%s "
  94. -                           "WHERE cookie=%s AND name=%s",
  95. -                           (int(time.time()), cookie.value, row[0]))
  96. +            @self.env.with_transaction()
  97. +            def update_auth_cookie(db):
  98. +                cursor.execute("UPDATE auth_cookie SET time=%s "
  99. +                               "WHERE cookie=%s AND name=%s",
  100. +                               (int(time.time()), cookie.value, row[0]))
  101.              req.outcookie['trac_auth'] = cookie.value
  102.              req.outcookie['trac_auth']['path'] = req.href()
  103.              req.outcookie['trac_auth']['expires'] = self.trac_auth_expires
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement