Update code in endpoints/login.post.py
This commit is contained in:
parent
ec243902c8
commit
f6c465a9ef
@ -1,33 +1,43 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from core.database import fake_users_db
|
||||
from core.auth import get_current_user_dummy
|
||||
import uuid
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/login")
|
||||
async def login_handler(
|
||||
username: str,
|
||||
password: str,
|
||||
username: str = "demo",
|
||||
password: str = "password"
|
||||
):
|
||||
"""Authenticate user and return access token"""
|
||||
"""Add predefined users and authenticate"""
|
||||
# Add predefined users if they don't exist
|
||||
if "Chidi" not in fake_users_db:
|
||||
fake_users_db["Chidi"] = {
|
||||
"id": str(uuid.uuid4()),
|
||||
"email": "chidi@example.com",
|
||||
"password": "chidi_password",
|
||||
"disabled": False
|
||||
}
|
||||
|
||||
if "Nneoma" not in fake_users_db:
|
||||
fake_users_db["Nneoma"] = {
|
||||
"id": str(uuid.uuid4()),
|
||||
"email": "nneoma@example.com",
|
||||
"password": "nneoma_password",
|
||||
"disabled": False
|
||||
}
|
||||
|
||||
user = fake_users_db.get(username)
|
||||
if not user or user["password"] != password:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Incorrect username or password"
|
||||
)
|
||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
||||
|
||||
return {
|
||||
"message": "Login successful",
|
||||
"user": {
|
||||
"username": username,
|
||||
"id": user["id"],
|
||||
"email": user["email"]
|
||||
},
|
||||
"token": "dummy_jwt_token_" + username,
|
||||
"message": "Login successful (demo)",
|
||||
"user": username,
|
||||
"token": "dummy_jwt_token_123",
|
||||
"features": {
|
||||
"rate_limit": 100,
|
||||
"expires_in": 3600,
|
||||
"permissions": ["read", "write"]
|
||||
}
|
||||
"expires_in": 3600
|
||||
},
|
||||
"available_users": ["Chidi", "Nneoma"]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user