Jon Solow
commited on
Commit
·
7804478
1
Parent(s):
d6188d7
Delete token then insert
Browse files- src/data_storage.py +7 -5
src/data_storage.py
CHANGED
@@ -95,14 +95,16 @@ def login_by_token(token: str):
|
|
95 |
def create_new_token_for_user(user_id: int, existing_user: bool = False):
|
96 |
# returns true if logged in successfully
|
97 |
token = token_urlsafe(32)
|
98 |
-
if existing_user:
|
99 |
-
sql_cmd = "REPLACE"
|
100 |
-
else:
|
101 |
-
sql_cmd = "INSERT"
|
102 |
with get_db_connection() as con:
|
103 |
cur = con.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
cur.execute(
|
105 |
-
f"""
|
106 |
VALUES({user_id}, '{token}')
|
107 |
"""
|
108 |
)
|
|
|
95 |
def create_new_token_for_user(user_id: int, existing_user: bool = False):
|
96 |
# returns true if logged in successfully
|
97 |
token = token_urlsafe(32)
|
|
|
|
|
|
|
|
|
98 |
with get_db_connection() as con:
|
99 |
cur = con.cursor()
|
100 |
+
if existing_user:
|
101 |
+
cur.execute(
|
102 |
+
f"""DELETE FROM tokens where user_id = {user_id}
|
103 |
+
"""
|
104 |
+
)
|
105 |
+
|
106 |
cur.execute(
|
107 |
+
f"""INSERT INTO tokens (user_id, token )
|
108 |
VALUES({user_id}, '{token}')
|
109 |
"""
|
110 |
)
|