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):