Spaces:
Sleeping
Sleeping
File size: 1,465 Bytes
5ea1351 37f0168 a6e5916 5ea1351 a6e5916 5ea1351 a6e5916 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 |
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(Dat: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='{Dat.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=Dat.Password==HasedPassword
if State:
connect.execute(f'''
INSERT INTO TrackeringPoints (UserId,Longtude ,Lattitude,Day,Houre) VALUES ({UserId},{float(Dat.Longtude)},{float(Dat.Lattitude)},'{Dat.Day}','{Dat.Houre}')
''')
connect.commit()
connect.close()
return {"State":True}
else:
return {"State":False}
except Exception as e :
return {"Status":False,"Message":e}
|