Update code in endpoints/login.post.py
This commit is contained in:
parent
0dda885b28
commit
5df7ada483
@ -1,25 +1,41 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from core.auth import get_current_user_dummy
|
||||
from core.database import fake_users_db
|
||||
import uuid
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/login")
|
||||
async def login_demo(
|
||||
username: str = "demo",
|
||||
password: str = "password"
|
||||
@router.post("/books")
|
||||
async def create_book(
|
||||
title: str,
|
||||
author: str,
|
||||
isbn: str = None,
|
||||
description: str = None
|
||||
):
|
||||
"""Demo login endpoint"""
|
||||
user = fake_users_db.get(username)
|
||||
if not user or user["password"] != password:
|
||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
||||
"""Create a new book entry"""
|
||||
book_id = str(uuid.uuid4())
|
||||
|
||||
if isbn in [book.get('isbn') for book in fake_users_db.get('books', [])]:
|
||||
raise HTTPException(status_code=400, detail="Book with this ISBN already exists")
|
||||
|
||||
new_book = {
|
||||
"id": book_id,
|
||||
"title": title,
|
||||
"author": author,
|
||||
"isbn": isbn,
|
||||
"description": description
|
||||
}
|
||||
|
||||
if 'books' not in fake_users_db:
|
||||
fake_users_db['books'] = []
|
||||
|
||||
fake_users_db['books'].append(new_book)
|
||||
|
||||
return {
|
||||
"message": "Login successful (demo)",
|
||||
"user": username,
|
||||
"token": "dummy_jwt_token_123",
|
||||
"features": {
|
||||
"rate_limit": 100,
|
||||
"expires_in": 3600
|
||||
"message": "Book created successfully",
|
||||
"book_id": book_id,
|
||||
"data": new_book,
|
||||
"metadata": {
|
||||
"timestamp": "demo_timestamp",
|
||||
"version": "1.0"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user