Update code in endpoints/login.post.py
This commit is contained in:
parent
96b995ebc1
commit
ec243902c8
@ -1,25 +1,33 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from core.auth import get_current_user_dummy
|
|
||||||
from core.database import fake_users_db
|
from core.database import fake_users_db
|
||||||
|
from core.auth import get_current_user_dummy
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/login")
|
@router.post("/login")
|
||||||
async def login_demo(
|
async def login_handler(
|
||||||
username: str = "demo",
|
username: str,
|
||||||
password: str = "password"
|
password: str,
|
||||||
):
|
):
|
||||||
"""Demo loginendpoint"""
|
"""Authenticate user and return access token"""
|
||||||
user = fake_users_db.get(username)
|
user = fake_users_db.get(username)
|
||||||
if not user or user["password"] != password:
|
if not user or user["password"] != password:
|
||||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
raise HTTPException(
|
||||||
|
status_code=400,
|
||||||
|
detail="Incorrect username or password"
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"message": "Login successful (demo)",
|
"message": "Login successful",
|
||||||
"user": username,
|
"user": {
|
||||||
"token": "dummy_jwt_token_123",
|
"username": username,
|
||||||
|
"id": user["id"],
|
||||||
|
"email": user["email"]
|
||||||
|
},
|
||||||
|
"token": "dummy_jwt_token_" + username,
|
||||||
"features": {
|
"features": {
|
||||||
"rate_limit": 100,
|
"rate_limit": 100,
|
||||||
"expires_in": 3600
|
"expires_in": 3600,
|
||||||
|
"permissions": ["read", "write"]
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user