From d816cd19123efd30fc358d4f5026860a05c31272 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Wed, 30 Oct 2024 19:41:48 +0100 Subject: [PATCH] Fix 4 --- auth/auth.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/auth/auth.py b/auth/auth.py index dfdfb3e..45950c4 100644 --- a/auth/auth.py +++ b/auth/auth.py @@ -29,22 +29,23 @@ class Authentication: return True def check_user(self, profileId, token, user): - with self.connect() as c: - res = c.execute("SELECT user FROM users WHERE profileId=?", - (profileId,)).fetchone() - if res is not None: - return res[0] == user - - # Check if new user can be created - res = c.execute("SELECT 1 FROM new WHERE user=?", - (user,)).fetchone() - if res is None or res[0] != 1: - return False - c.execute("DELETE FROM new WHERE user=?", (user,)) - - # Create new user - c.execute("INSERT INTO users VALUES (?, ?, ?)", - (profileId, token, user)) + with self.connect() as con: + with con.cursor() as c: + res = c.execute("SELECT user FROM users WHERE profileId=?", + (profileId,)).fetchone() + if res is not None: + return res[0] == user + + # Check if new user can be created + res = c.execute("SELECT 1 FROM new WHERE user=?", + (user,)).fetchone() + if res is None or res[0] != 1: + return False + + # Create new user + c.execute("DELETE FROM new WHERE user=?", (user,)) + c.execute("INSERT INTO users VALUES (?, ?, ?)", + (profileId, token, user)) return True def get_user(self, profileId):