Add in authentication via Flask-Login, still need to modify http functions so they are linked to a user

This commit is contained in:
Peter Stockings
2023-12-20 22:26:11 +11:00
parent 6a894df009
commit 30e16277df
5 changed files with 210 additions and 2 deletions

17
db.py
View File

@@ -83,4 +83,19 @@ class DataBase():
FROM http_function_invocations
WHERE http_function_id=%s
ORDER BY invocation_time DESC""", [http_function_id])
return http_function_invocations
return http_function_invocations
def get_user(self, user_id):
user = self.execute(
'SELECT id, username, password_hash, created_at FROM users WHERE id=%s', [int(user_id)], one=True)
return user
def get_user_by_username(self, username):
user = self.execute(
'SELECT id, username, password_hash, created_at FROM users WHERE username=%s', [username], one=True)
return user
def create_new_user(self, username, password_hash):
new_user = self.execute(
'INSERT INTO users (username, password_hash) VALUES (%s, %s) RETURNING id, username, password_hash, created_at', [username, password_hash], commit=True)
return new_user