Update code in endpoints/login.post.py
This commit is contained in:
parent
485432a8b1
commit
168647f932
@ -1,37 +1,34 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from pydantic import BaseModel
|
|
||||||
from datetime import timedelta
|
prices = [] # In-memory storage
|
||||||
from core.database import get_db
|
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
from core.auth import verify_password, create_access_token
|
|
||||||
from models.user import User
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
class UserAuth(BaseModel):
|
@router.post("/petrol-price")
|
||||||
username: str
|
async def update_petrol_price(
|
||||||
password: str
|
price: float = 650.00,
|
||||||
|
state: str = "Lagos",
|
||||||
@router.post("/login")
|
station: str = "NNPC"
|
||||||
async def login(
|
|
||||||
user_data: UserAuth,
|
|
||||||
db: Session = Depends(get_db)
|
|
||||||
):
|
):
|
||||||
"""User authentication endpoint"""
|
"""Update petrol price endpoint"""
|
||||||
user = db.query(User).filter(User.username == user_data.username).first()
|
if price <= 0:
|
||||||
|
raise HTTPException(status_code=400, detail="Invalid price amount")
|
||||||
if not user or not verify_password(user_data.password, user.hashed_password):
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
prices.append({
|
||||||
|
"price_per_litre": price,
|
||||||
# Generate token with expiration
|
"state": state,
|
||||||
access_token = create_access_token(
|
"station": station,
|
||||||
data={"sub": user.id},
|
"currency": "NGN",
|
||||||
expires_delta=timedelta(hours=1)
|
"last_updated": "2024-01-19"
|
||||||
)
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"access_token": access_token,
|
"message": "Price updated successfully",
|
||||||
"token_type": "bearer",
|
"price": price,
|
||||||
"user_id": user.id,
|
"state": state,
|
||||||
"username": user.username
|
"station": station,
|
||||||
}
|
"features": {
|
||||||
|
"rate_limit": 100,
|
||||||
|
"expires_in": 3600
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user