Spaces:
Sleeping
Sleeping
| from fastapi import APIRouter | |
| import sqlite3 | |
| from passlib.context import CryptContext | |
| from shutil import rmtree | |
| from os.path import exists | |
| DeleteUserRouter=APIRouter(prefix="/Users") | |
| def SpeachToTextEndPoint(Email:str,Password:str,AdminEmail:str,AdminPassword:str): | |
| try: | |
| if AdminEmail !="Mhammed@Admin.com" 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} |