Graduation / Logic /FUsers /AddUserItem.py
Mohammedallyl's picture
Upload 27 files
c4dc0b3 verified
raw
history blame
2.16 kB
from fastapi import APIRouter,File,Form,UploadFile
import sqlite3
from os.path import exists
from os import makedirs
from PIL import Image
from io import BytesIO
UserItemAddRouter=APIRouter(prefix="/Users")
@UserItemAddRouter.post("/AddUserItem")
def adduser(Email:str=Form(...),Name:str=Form(...),Password:str=Form(...),Images:UploadFile=File(...)):
try:
State=False
connect=sqlite3.connect("DataBase/DataBase.bd")
cursor=connect.execute(f'''
SELECT UserId,Password FROM Users where Email='{ Email}'
''')
FData=cursor.fetchall()
if len(FData) !=0 :
if FData[0][0]==None:
return {"Status":False,"Message":"Email or Password Is Incorrect "}
HasedPassword=FData[0][1]
UserId=FData[0][0]
State= Password==HasedPassword
Name= Name
if not State:
return {"Status":False,"Message":"Email or Password is not correct"}
if not exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{Name}"):
connect.execute(f'''
INSERT INTO UserItems (UserId ,UserItemName ) VALUES ({UserId},'{Name}')
''')
connect.commit()
if not exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{Name}"):
makedirs(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{Name}")
if not exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Test/{Name}"):
makedirs(f"./FaceRecognition/ExtactedFaces/{UserId}/Test/{Name}")
if not exists(f"./static/{UserId}/{Name}"):
makedirs(f"./static/{UserId}/{Name}")
Image.open(BytesIO(Images.file.read())).save(f"./static/{UserId}/{Name}/user.png","PNG")
return {"Status":True,"Message":"User Is Added Correctly"}
else:
return {"Status":False,"Message":"Name Is Already Exist"}
except Exception as e:
return {"Status":False,"Message":e}