Skip to content
Snippets Groups Projects
Unverified Commit 3957ea7d authored by Shamil K Muhammed's avatar Shamil K Muhammed
Browse files

Use the `with` statement on the connection object

Before, v.0.0.3, the connection was reinitialized everytime a new
auth request was sent to the module. But after that version, things
changed and a single connection was used.

This caused #2. It was because the transactions weren't commited
before querying again. Which stops the auth provider from getting
new data. So, the context manager is also used on the connection
everytime a query is sent to ensure the transactions are committed.

So, hopefully this commit fixes #2
parent 2c36ac91
No related merge requests found
......@@ -22,13 +22,13 @@ import bcrypt
import logging
__VERSION__ = "0.0.4"
__VERSION__ = "0.0.5"
logger = logging.getLogger(__name__)
class DiasporaAuthProvider:
__version__ = "0.0.4"
__version__ = "0.0.5"
def __init__(self, config, account_handler):
self.account_handler = account_handler
......@@ -55,15 +55,16 @@ class DiasporaAuthProvider:
local_part = user_id.split(':', 1)[0][1:]
logger.info("Checking if user {} exists.".format(local_part))
try:
with self.connection.cursor() as cursor:
yield threads.deferToThread( # Don't think this is needed, but w/e
cursor.execute,
"SELECT username, encrypted_password FROM users WHERE username=%s",
(local_part,)
)
user = yield threads.deferToThread(
cursor.fetchone
)
with self.connection:
with self.connection.cursor() as cursor:
yield threads.deferToThread( # Don't think this is needed, but w/e
cursor.execute,
"SELECT username, encrypted_password FROM users WHERE username=%s",
(local_part,)
)
user = yield threads.deferToThread(
cursor.fetchone
)
# check if the user exists.
if not user:
logger.info("User {} does not exist. Rejecting auth request".format(local_part))
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment