from fastapi import APIRouter import sqlite3 from passlib.context import CryptContext from pydantic import BaseModel class DataType(BaseModel): Email:str Password:str Longtude:str Lattitude:str Day:str Houre:str UserAddLocationRouter=APIRouter(prefix="/Location") @UserAddLocationRouter.post("/AddLocation") def adduser(Data:DataType): try: 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='{Data.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=Data.Password==HasedPassword if State: connect.execute(f''' INSERT INTO TrackeringPoints (UserId,Longtude ,Lattitude,Day,Houre) VALUES ({UserId},{float(Data.Longtude)},{float(Data.Lattitude)},'{Data.Day}','{Data.Houre}') ''') connect.commit() connect.close() return {"State":True} else: return {"State":False} except Exception as e : return {"Status":False,"Message":e}