Spaces:
Sleeping
Sleeping
File size: 1,809 Bytes
c4dc0b3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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} |