diff --git a/backend/data/project-files/19/WhatsApp Image 2024-09-02 at 5.34.42 AM.jpeg b/backend/data/project-files/19/WhatsApp Image 2024-09-02 at 5.34.42 AM.jpeg new file mode 100644 index 0000000..31c19a2 Binary files /dev/null and b/backend/data/project-files/19/WhatsApp Image 2024-09-02 at 5.34.42 AM.jpeg differ diff --git a/backend/data/project-files/19/image_gallery_v1.0.2.gif b/backend/data/project-files/19/image_gallery_v1.0.2.gif new file mode 100644 index 0000000..0b1e97e Binary files /dev/null and b/backend/data/project-files/19/image_gallery_v1.0.2.gif differ diff --git a/backend/data/project-files/22/aidssch (1).pdf b/backend/data/project-files/22/aidssch (1).pdf new file mode 100644 index 0000000..19511d5 Binary files /dev/null and b/backend/data/project-files/22/aidssch (1).pdf differ diff --git a/backend/data/sqlite-database.db b/backend/data/sqlite-database.db index 129bd78..2a1b9d1 100644 Binary files a/backend/data/sqlite-database.db and b/backend/data/sqlite-database.db differ diff --git a/backend/src/rest_api.py b/backend/src/rest_api.py index ce6bb0d..ad9dc1b 100644 --- a/backend/src/rest_api.py +++ b/backend/src/rest_api.py @@ -19,7 +19,8 @@ def register_mail() -> flask.Response: return flask.Response(f"mail or password is missing", 422) try: utils.MailHandler.send_code(mail) - except Exception: + except Exception as e: + print(e) return flask.Response("Something went wrong, check mail or try again later", 404) response = flask.Response() response.set_cookie("mail", mail) diff --git a/backend/src/utils/team.py b/backend/src/utils/team.py index 394557b..c77dbda 100644 --- a/backend/src/utils/team.py +++ b/backend/src/utils/team.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -import sqlite3 +import mariadb @dataclass @@ -48,22 +48,36 @@ class Team: class TeamHandler: - __connection: sqlite3.Connection = sqlite3.connect("../data/sqlite-database.db", check_same_thread=False) - __cursor: sqlite3.Cursor = __connection.cursor() + @classmethod + def init(cls): + cls.__connection = mariadb.connect( + user="mariadb", + password="", + host="localhost", + port=3306, + database="ssth") + cls.__cursor = cls.__connection.cursor() + + @classmethod + def close(cls) -> None: + cls.__connection.commit() + cls.__connection.close() @classmethod def create_team(cls, team_name: str) -> int: + cls.init() team = cls.__cursor.execute( """ INSERT INTO teams(team_name) VALUES(?) """, (team_name, ) ) - cls.__connection.commit() + cls.close() return team.lastrowid if team.lastrowid else -1 @classmethod def get_team_members(cls, team_id: int) -> list[int]: + cls.init() users = cls.__cursor.execute( f""" SELECT user_id @@ -71,6 +85,7 @@ class TeamHandler: """, (team_id, ) ).fetchall() + cls.close() return [user[0] for user in users] @classmethod @@ -78,6 +93,7 @@ class TeamHandler: cls, team: Team, ) -> None: + cls.init() cls.__cursor.execute( f""" UPDATE teams SET @@ -107,15 +123,17 @@ class TeamHandler: team.team_id, ) ) - cls.__connection.commit() + cls.close() @classmethod def get_project(cls, team_id: int) -> Team: + cls.init() teams = cls.__cursor.execute( f""" SELECT * FROM teams WHERE team_id = ? """, (team_id, ) ).fetchall()[0] + cls.close() return Team( teams[0], teams[1], diff --git a/backend/src/utils/user.py b/backend/src/utils/user.py index 4c68fa7..c1511e6 100644 --- a/backend/src/utils/user.py +++ b/backend/src/utils/user.py @@ -1,6 +1,6 @@ import bcrypt from dataclasses import dataclass -import sqlite3 +import mariadb import utils @@ -62,14 +62,27 @@ class User: return the_dict class UserHandler: - __connection: sqlite3.Connection = sqlite3.connect("../data/sqlite-database.db", check_same_thread=False) - __cursor: sqlite3.Cursor = __connection.cursor() + @classmethod + def init(cls): + cls.__connection = mariadb.connect( + user="mariadb", + password="", + host="localhost", + port=3306, + database="ssth") + cls.__cursor = cls.__connection.cursor() + + @classmethod + def close(cls) -> None: + cls.__connection.commit() + cls.__connection.close() @classmethod def create_user( cls, user: User ) -> None: + cls.init() assert len(utils.TeamHandler.get_team_members(user.team_id)) < 4 salt = bcrypt.gensalt() encrypted_password = bcrypt.hashpw(user.password.encode("utf-8"), salt) @@ -110,10 +123,11 @@ class UserHandler: user.team_leader, ) ) - cls.__connection.commit() + cls.close() @classmethod def get_user_by_id(cls, user_id: int) -> User: + cls.init() users = cls.__cursor.execute( f""" SELECT * @@ -123,6 +137,7 @@ class UserHandler: ).fetchall() assert users, f"{user_id} does not exist!" user = users[0] + cls.close() return User( user[0], user[1], @@ -153,6 +168,7 @@ class UserHandler: if not users: raise KeyError(f"{mail} does not exist!") user = users[0] + cls.close() return User( user[0], user[1], @@ -173,6 +189,7 @@ class UserHandler: @classmethod def verify_password_by_mail(cls, mail: str, password: str) -> bool: + cls.init() users = cls.__cursor.execute( f""" SELECT password @@ -182,6 +199,7 @@ class UserHandler: ).fetchall() if not users: raise KeyError(f"{mail} does not exist!") + cls.close() return bcrypt.checkpw( password.encode("utf-8"), users[0][0] @@ -189,10 +207,11 @@ class UserHandler: @classmethod def delete_member(cls, mail: str, leader_id: int) -> None: + cls.init() assert cls.get_user_by_id(leader_id).team_id == cls.get_user_by_mail(mail).team_id cls.__cursor.execute( f""" DELETE FROM users WHERE mail=? """, (mail, ) ) - cls.__connection.commit() + cls.close()