Something
This commit is contained in:
parent
2d630a62f3
commit
b5bf60d4d2
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
backend/data/project-files/19/image_gallery_v1.0.2.gif
Normal file
BIN
backend/data/project-files/19/image_gallery_v1.0.2.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 MiB |
BIN
backend/data/project-files/22/aidssch (1).pdf
Normal file
BIN
backend/data/project-files/22/aidssch (1).pdf
Normal file
Binary file not shown.
Binary file not shown.
@ -19,7 +19,8 @@ def register_mail() -> flask.Response:
|
|||||||
return flask.Response(f"mail or password is missing", 422)
|
return flask.Response(f"mail or password is missing", 422)
|
||||||
try:
|
try:
|
||||||
utils.MailHandler.send_code(mail)
|
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)
|
return flask.Response("Something went wrong, check mail or try again later", 404)
|
||||||
response = flask.Response()
|
response = flask.Response()
|
||||||
response.set_cookie("mail", mail)
|
response.set_cookie("mail", mail)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import sqlite3
|
import mariadb
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -48,22 +48,36 @@ class Team:
|
|||||||
|
|
||||||
|
|
||||||
class TeamHandler:
|
class TeamHandler:
|
||||||
__connection: sqlite3.Connection = sqlite3.connect("../data/sqlite-database.db", check_same_thread=False)
|
@classmethod
|
||||||
__cursor: sqlite3.Cursor = __connection.cursor()
|
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
|
@classmethod
|
||||||
def create_team(cls, team_name: str) -> int:
|
def create_team(cls, team_name: str) -> int:
|
||||||
|
cls.init()
|
||||||
team = cls.__cursor.execute(
|
team = cls.__cursor.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO teams(team_name) VALUES(?)
|
INSERT INTO teams(team_name) VALUES(?)
|
||||||
""",
|
""",
|
||||||
(team_name, )
|
(team_name, )
|
||||||
)
|
)
|
||||||
cls.__connection.commit()
|
cls.close()
|
||||||
return team.lastrowid if team.lastrowid else -1
|
return team.lastrowid if team.lastrowid else -1
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_team_members(cls, team_id: int) -> list[int]:
|
def get_team_members(cls, team_id: int) -> list[int]:
|
||||||
|
cls.init()
|
||||||
users = cls.__cursor.execute(
|
users = cls.__cursor.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT user_id
|
SELECT user_id
|
||||||
@ -71,6 +85,7 @@ class TeamHandler:
|
|||||||
""",
|
""",
|
||||||
(team_id, )
|
(team_id, )
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
cls.close()
|
||||||
return [user[0] for user in users]
|
return [user[0] for user in users]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -78,6 +93,7 @@ class TeamHandler:
|
|||||||
cls,
|
cls,
|
||||||
team: Team,
|
team: Team,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
cls.init()
|
||||||
cls.__cursor.execute(
|
cls.__cursor.execute(
|
||||||
f"""
|
f"""
|
||||||
UPDATE teams SET
|
UPDATE teams SET
|
||||||
@ -107,15 +123,17 @@ class TeamHandler:
|
|||||||
team.team_id,
|
team.team_id,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
cls.__connection.commit()
|
cls.close()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_project(cls, team_id: int) -> Team:
|
def get_project(cls, team_id: int) -> Team:
|
||||||
|
cls.init()
|
||||||
teams = cls.__cursor.execute(
|
teams = cls.__cursor.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT * FROM teams WHERE team_id = ?
|
SELECT * FROM teams WHERE team_id = ?
|
||||||
""", (team_id, )
|
""", (team_id, )
|
||||||
).fetchall()[0]
|
).fetchall()[0]
|
||||||
|
cls.close()
|
||||||
return Team(
|
return Team(
|
||||||
teams[0],
|
teams[0],
|
||||||
teams[1],
|
teams[1],
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import bcrypt
|
import bcrypt
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import sqlite3
|
import mariadb
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
|
|
||||||
@ -62,14 +62,27 @@ class User:
|
|||||||
return the_dict
|
return the_dict
|
||||||
|
|
||||||
class UserHandler:
|
class UserHandler:
|
||||||
__connection: sqlite3.Connection = sqlite3.connect("../data/sqlite-database.db", check_same_thread=False)
|
@classmethod
|
||||||
__cursor: sqlite3.Cursor = __connection.cursor()
|
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
|
@classmethod
|
||||||
def create_user(
|
def create_user(
|
||||||
cls,
|
cls,
|
||||||
user: User
|
user: User
|
||||||
) -> None:
|
) -> None:
|
||||||
|
cls.init()
|
||||||
assert len(utils.TeamHandler.get_team_members(user.team_id)) < 4
|
assert len(utils.TeamHandler.get_team_members(user.team_id)) < 4
|
||||||
salt = bcrypt.gensalt()
|
salt = bcrypt.gensalt()
|
||||||
encrypted_password = bcrypt.hashpw(user.password.encode("utf-8"), salt)
|
encrypted_password = bcrypt.hashpw(user.password.encode("utf-8"), salt)
|
||||||
@ -110,10 +123,11 @@ class UserHandler:
|
|||||||
user.team_leader,
|
user.team_leader,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
cls.__connection.commit()
|
cls.close()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_user_by_id(cls, user_id: int) -> User:
|
def get_user_by_id(cls, user_id: int) -> User:
|
||||||
|
cls.init()
|
||||||
users = cls.__cursor.execute(
|
users = cls.__cursor.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT *
|
SELECT *
|
||||||
@ -123,6 +137,7 @@ class UserHandler:
|
|||||||
).fetchall()
|
).fetchall()
|
||||||
assert users, f"{user_id} does not exist!"
|
assert users, f"{user_id} does not exist!"
|
||||||
user = users[0]
|
user = users[0]
|
||||||
|
cls.close()
|
||||||
return User(
|
return User(
|
||||||
user[0],
|
user[0],
|
||||||
user[1],
|
user[1],
|
||||||
@ -153,6 +168,7 @@ class UserHandler:
|
|||||||
if not users:
|
if not users:
|
||||||
raise KeyError(f"{mail} does not exist!")
|
raise KeyError(f"{mail} does not exist!")
|
||||||
user = users[0]
|
user = users[0]
|
||||||
|
cls.close()
|
||||||
return User(
|
return User(
|
||||||
user[0],
|
user[0],
|
||||||
user[1],
|
user[1],
|
||||||
@ -173,6 +189,7 @@ class UserHandler:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def verify_password_by_mail(cls, mail: str, password: str) -> bool:
|
def verify_password_by_mail(cls, mail: str, password: str) -> bool:
|
||||||
|
cls.init()
|
||||||
users = cls.__cursor.execute(
|
users = cls.__cursor.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT password
|
SELECT password
|
||||||
@ -182,6 +199,7 @@ class UserHandler:
|
|||||||
).fetchall()
|
).fetchall()
|
||||||
if not users:
|
if not users:
|
||||||
raise KeyError(f"{mail} does not exist!")
|
raise KeyError(f"{mail} does not exist!")
|
||||||
|
cls.close()
|
||||||
return bcrypt.checkpw(
|
return bcrypt.checkpw(
|
||||||
password.encode("utf-8"),
|
password.encode("utf-8"),
|
||||||
users[0][0]
|
users[0][0]
|
||||||
@ -189,10 +207,11 @@ class UserHandler:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete_member(cls, mail: str, leader_id: int) -> None:
|
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
|
assert cls.get_user_by_id(leader_id).team_id == cls.get_user_by_mail(mail).team_id
|
||||||
cls.__cursor.execute(
|
cls.__cursor.execute(
|
||||||
f"""
|
f"""
|
||||||
DELETE FROM users WHERE mail=?
|
DELETE FROM users WHERE mail=?
|
||||||
""", (mail, )
|
""", (mail, )
|
||||||
)
|
)
|
||||||
cls.__connection.commit()
|
cls.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user