worked on system, added member, advisor & admin management.

This commit is contained in:
2022-10-05 21:47:05 +02:00
parent dac0fea952
commit a55017b23d
14 changed files with 522 additions and 35 deletions

View File

@@ -3,6 +3,10 @@ from models.user import User
class Auth:
def check_auth(username, password):
if username == "superadmin" and password == "Admin321!":
su_user = User(None, -1, "superadmin", "", "", "", "", "", "", "", "", "SUPER_ADMIN")
return su_user
user = User(Database.connection, None, username)
if user.load_by_username() and user.password == password:
return user

69
services/search.py Normal file
View File

@@ -0,0 +1,69 @@
from models.database import Database
from models.user import User
class Search:
@staticmethod
def search_members(query):
cur = Database.connection.cursor()
cur.execute("""
SELECT * FROM users WHERE
id LIKE ? OR
username LIKE ? OR
firstname LIKE ? OR
lastname LIKE ? OR
email LIKE ? OR
phone LIKE ?
""", (f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%"))
rows = cur.fetchall()
payload = []
for row in rows:
user = User(Database.connection)._set_row_values(row)
if user.role == "MEMBER":
payload.append(user)
return payload
@staticmethod
def search_advisors(query):
cur = Database.connection.cursor()
cur.execute("""
SELECT * FROM users WHERE
id LIKE ? OR
username LIKE ? OR
firstname LIKE ? OR
lastname LIKE ? OR
email LIKE ? OR
phone LIKE ?
""", (f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%"))
rows = cur.fetchall()
payload = []
for row in rows:
user = User(Database.connection)._set_row_values(row)
if user.role == "ADVISOR":
payload.append(user)
return payload
@staticmethod
def search_admins(query):
cur = Database.connection.cursor()
cur.execute("""
SELECT * FROM users WHERE
id LIKE ? OR
username LIKE ? OR
firstname LIKE ? OR
lastname LIKE ? OR
email LIKE ? OR
phone LIKE ?
""", (f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%", f"%{query}%"))
rows = cur.fetchall()
payload = []
for row in rows:
user = User(Database.connection)._set_row_values(row)
if user.role == "SYSTEM_ADMIN":
payload.append(user)
return payload

7
services/utils.py Normal file
View File

@@ -0,0 +1,7 @@
import os
class Utils:
@staticmethod
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')