Update code in endpoints/login.post.py
This commit is contained in:
parent
fcba290d7e
commit
cb45026fef
@ -1,37 +1,34 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from pydantic import BaseModel
|
from typing import List
|
||||||
from datetime import timedelta
|
|
||||||
from core.database import get_db
|
images = [] # In-memory storage
|
||||||
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):
|
|
||||||
username: str
|
|
||||||
password: str
|
|
||||||
|
|
||||||
@router.post("/login")
|
@router.post("/login")
|
||||||
async def login(
|
async def detect_image(
|
||||||
user_data: UserAuth,
|
image_url: str = "https://example.com/image.jpg",
|
||||||
db: Session = Depends(get_db)
|
detection_type: str = "objects"
|
||||||
):
|
):
|
||||||
"""User authentication endpoint"""
|
"""Demo image detection endpoint"""
|
||||||
user = db.query(User).filter(User.username == user_data.username).first()
|
if not image_url:
|
||||||
|
raise HTTPException(status_code=400, detail="Image URL required")
|
||||||
|
|
||||||
if not user or not verify_password(user_data.password, user.hashed_password):
|
# Demo detection response
|
||||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
detection_result = {
|
||||||
|
"message": "Detection successful (demo)",
|
||||||
# Generate token with expiration
|
"image": image_url,
|
||||||
access_token = create_access_token(
|
"detections": [
|
||||||
data={"sub": user.id},
|
{
|
||||||
expires_delta=timedelta(hours=1)
|
"label": "person",
|
||||||
)
|
"confidence": 0.95,
|
||||||
|
"bbox": [100, 200, 300, 400]
|
||||||
return {
|
}
|
||||||
"access_token": access_token,
|
],
|
||||||
"token_type": "bearer",
|
"features": {
|
||||||
"user_id": user.id,
|
"rate_limit": 100,
|
||||||
"username": user.username
|
"expires_in": 3600
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return detection_result
|
Loading…
x
Reference in New Issue
Block a user