36 lines
982 B
Python
36 lines
982 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy import Column, String, Boolean
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
Base = declarative_base()
|
|
router = APIRouter()
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(String, primary_key=True)
|
|
token = Column(String, nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
@router.post("/logout")
|
|
async def logout_demo(
|
|
user_id: str = "demo_user",
|
|
token: str = "dummy_jwt_token_123"
|
|
):
|
|
"""Demo logout endpoint"""
|
|
if not any(u.id == user_id for u in User.query.all()):
|
|
raise HTTPException(status_code=400, detail="Invalid user")
|
|
|
|
user = User.query.filter_by(id=user_id).first()
|
|
user.token = None
|
|
user.is_active = False
|
|
|
|
return {
|
|
"message": "Logout successful",
|
|
"user": user_id,
|
|
"session_ended": True,
|
|
"features": {
|
|
"can_relogin": True,
|
|
"cooldown_period": 0
|
|
}
|
|
} |