Graduation / Logic /FUsers /DeleteUserItem.py
Mohammedallyl's picture
Upload 27 files
c4dc0b3 verified
from fastapi import APIRouter
import sqlite3
from passlib.context import CryptContext
from shutil import rmtree
from os.path import exists
from pydantic import BaseModel
class DataType(BaseModel):
Email:str
Name:str
Password:str
UserItemDeleteRouter=APIRouter(prefix="/Users")
@UserItemDeleteRouter.post("/DeleteUserItem")
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"}
Name=Dat.Name
connect.execute(f'''
DELETE FROM UserItems WHERE UserId={UserId} AND UserItemName='{Name}'
''')
connect.commit()
if exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Test/{Name}"):
rmtree(f"./FaceRecognition/ExtactedFaces/{UserId}/Test/{Name}")
if exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{Name}"):
rmtree(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{Name}")
else:
return {"Status":False,"Message":"User Is Not Founded"}
return {"Status":True,"Message":"User Is Deleted Correctly"}
except sqlite3.Error as e:
return {"Status":False,"Message":e}