Spaces:
Sleeping
Sleeping
File size: 1,851 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
DeleteUserRouter=APIRouter(prefix="/Users")
@DeleteUserRouter.post("/DeleteUser")
def SpeachToTextEndPoint(Email:str,Password:str,AdminEmail:str,AdminPassword:str):
try:
if AdminEmail !="[email protected]" and AdminPassword !="#mohammed*123#":
return {"Status":False,"Message":" Admin Email or Password is not correct "}
State=False
pwd_context=CryptContext(schemes=["bcrypt"],deprecated="auto")
connect=sqlite3.connect("DataBase/DataBase.bd")
cursor=connect.execute(f'''
SELECT UserId,Password FROM Users where Email='{Email}'
''')
Data=cursor.fetchall()
if len(Data) !=0 :
if Data[0][0]==None:
return {"Status":True,"Message":"User Is Not Defined Before"}
HasedPassword=Data[0][1]
UserId=Data[0][0]
State=pwd_context.verify(Password,HasedPassword)
if State:
connect.execute(f'''
DELETE FROM Users where Email='{Email}'
''')
connect.execute(f'''
DELETE FROM UserItems WHERE UserId={UserId}
''')
connect.commit()
if exists(f"./FaceRecognition/ExtactedFaces/{UserId}"):
rmtree(f"./FaceRecognition/ExtactedFaces/{UserId}")
return {"Status":True,"Message":"User Is Deleted Correctly"}
else:
return {"Status":False,"Message":"Email or Password is not correct"}
except sqlite3.Error as e:
return {"Status":False,"Message":e} |