Graduation / Logic /FUsers /GetUsersItems.py
Mohammedallyl's picture
Upload 27 files
c4dc0b3 verified
from fastapi import APIRouter
import sqlite3
from os import listdir
from os.path import exists
from pydantic import BaseModel
class DataType(BaseModel):
Email:str
Password:str
# from jose import jwt,JWTError
UserItemGetRouter=APIRouter(prefix="/Users")
@UserItemGetRouter.post("/GetUserItem")
def adduser(Dat:DataType):
try:
State=False
connect=sqlite3.connect("DataBase/DataBase.bd")
cursor=connect.execute(f'''
SELECT UserId,Password FROM Users where Email='{Dat.Email}'
''')
Data=cursor.fetchall()
if len(Data)!=0:
if Data[0][0]==None:
return {"Status":False,"Message":"Email or Password Is Incorrect "}
HasedPassword=Data[0][1]
UserId=Data[0][0]
State=Dat.Password==HasedPassword
if not State:
return {"Status":False,"Message":"Email or Password is not correct"}
cursor=connect.execute(f'''
SELECT UserItemName FROM UserItems where UserId={UserId}
''')
Data=cursor.fetchall()
if len(Data)!=0:
if Data[0][0]==None:
return {"Status":True,"Data":[]}
else:
UsersItems=[]
for i in Data:
num=0
if exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{i[0]}"):
num=len(listdir(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{i[0]}"))
UsersItems.append({"Name":i[0],"NumImages":num})
return {"Status":True,"Data":UsersItems}
return {"Status":False,"Message":[]}
except Exception as e:
return {"Status":False,"Message":e}