- Replace email with username for authentication - Update User model, schemas, and auth endpoints - Update frontend login and register views - Add migration to remove email column - Add multiple track upload support - New backend endpoint for bulk upload - Frontend multi-file selection with progress - Auto-extract metadata from ID3 tags - Visual upload progress for each file - Prevent duplicate tracks in room queue - Backend validation for duplicates - Visual indication of tracks already in queue - Error handling with user feedback - Add bulk track selection for rooms - Multi-select mode with checkboxes - Bulk add endpoint with duplicate filtering - Selection counter and controls - Add track filters in room modal - Search by title and artist - Filter by "My tracks" - Filter by "Not in queue" - Live filtering with result counter - Improve Makefile - Add build-backend and build-frontend commands - Add rebuild-backend and rebuild-frontend commands - Add rebuild-clean variants - Update migrations to run in Docker 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select
|
|
from ..database import get_db
|
|
from ..models.user import User
|
|
from ..schemas.user import UserCreate, UserLogin, UserResponse, Token
|
|
from ..utils.security import get_password_hash, verify_password, create_access_token
|
|
from ..services.auth import get_current_user
|
|
|
|
router = APIRouter(prefix="/api/auth", tags=["auth"])
|
|
|
|
|
|
@router.post("/register", response_model=Token)
|
|
async def register(user_data: UserCreate, db: AsyncSession = Depends(get_db)):
|
|
# Check if username exists
|
|
result = await db.execute(select(User).where(User.username == user_data.username))
|
|
if result.scalar_one_or_none():
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="Username already taken",
|
|
)
|
|
|
|
# Create user
|
|
user = User(
|
|
username=user_data.username,
|
|
password_hash=get_password_hash(user_data.password),
|
|
)
|
|
db.add(user)
|
|
await db.flush()
|
|
|
|
# Create token
|
|
access_token = create_access_token(data={"sub": str(user.id)})
|
|
return Token(access_token=access_token)
|
|
|
|
|
|
@router.post("/login", response_model=Token)
|
|
async def login(user_data: UserLogin, db: AsyncSession = Depends(get_db)):
|
|
result = await db.execute(select(User).where(User.username == user_data.username))
|
|
user = result.scalar_one_or_none()
|
|
|
|
if not user or not verify_password(user_data.password, user.password_hash):
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Invalid username or password",
|
|
)
|
|
|
|
access_token = create_access_token(data={"sub": str(user.id)})
|
|
return Token(access_token=access_token)
|
|
|
|
|
|
@router.get("/me", response_model=UserResponse)
|
|
async def get_me(current_user: User = Depends(get_current_user)):
|
|
return current_user
|