Update code in endpoints/login.post.py
This commit is contained in:
parent
5f5da9fc88
commit
5f18e055b5
@ -1,37 +1,36 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from pydantic import BaseModel
|
import uuid
|
||||||
from datetime import timedelta
|
|
||||||
from core.database import get_db
|
playlists = [] # 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 create_playlist(
|
||||||
user_data: UserAuth,
|
name: str = "My Playlist",
|
||||||
db: Session = Depends(get_db)
|
description: str = "My awesome playlist",
|
||||||
|
user_id: str = "user_123"
|
||||||
):
|
):
|
||||||
"""User authentication endpoint"""
|
"""Create new playlist endpoint"""
|
||||||
user = db.query(User).filter(User.username == user_data.username).first()
|
playlist_id = str(uuid.uuid4())
|
||||||
|
|
||||||
if not user or not verify_password(user_data.password, user.hashed_password):
|
playlist = {
|
||||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
"id": playlist_id,
|
||||||
|
"name": name,
|
||||||
# Generate token with expiration
|
"description": description,
|
||||||
access_token = create_access_token(
|
"user_id": user_id,
|
||||||
data={"sub": user.id},
|
"tracks": [],
|
||||||
expires_delta=timedelta(hours=1)
|
"created_at": "2024-01-01T00:00:00Z"
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"access_token": access_token,
|
|
||||||
"token_type": "bearer",
|
|
||||||
"user_id": user.id,
|
|
||||||
"username": user.username
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playlists.append(playlist)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "Playlist created successfully",
|
||||||
|
"playlist_id": playlist_id,
|
||||||
|
"name": name,
|
||||||
|
"features": {
|
||||||
|
"max_tracks": 100,
|
||||||
|
"visibility": "public"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user