Update code in endpoints/login.post.py
This commit is contained in:
parent
5b690688d6
commit
a77803fcba
@ -1,25 +1,45 @@
|
||||
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("/organizations/add-user")
|
||||
async def add_user_to_organization(
|
||||
organization_id: str,
|
||||
user_id: str,
|
||||
role: str = "member"
|
||||
):
|
||||
"""Demo login endpoint"""
|
||||
user = fake_users_db.get(username)
|
||||
if not user or user["password"] != password:
|
||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
||||
"""Add user to organization"""
|
||||
if organization_id not in fake_users_db.get("organizations", {}):
|
||||
raise HTTPException(status_code=404, detail="Organization not found")
|
||||
|
||||
if user_id not in fake_users_db:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
membership_id = str(uuid.uuid4())
|
||||
|
||||
if "memberships" not in fake_users_db:
|
||||
fake_users_db["memberships"] = {}
|
||||
|
||||
fake_users_db["memberships"][membership_id] = {
|
||||
"id": membership_id,
|
||||
"user_id": user_id,
|
||||
"organization_id": organization_id,
|
||||
"role": role,
|
||||
"created_at": "2024-01-01T00:00:00Z" # Demo timestamp
|
||||
}
|
||||
|
||||
return {
|
||||
"message": "Login successful (demo)",
|
||||
"user": username,
|
||||
"token": "dummy_jwt_token_123",
|
||||
"features": {
|
||||
"rate_limit": 100,
|
||||
"expires_in": 3600
|
||||
}
|
||||
}
|
||||
"message": "User added to organization successfully",
|
||||
"data": {
|
||||
"membership_id": membership_id,
|
||||
"user_id": user_id,
|
||||
"organization_id": organization_id,
|
||||
"role": role
|
||||
},
|
||||
"next_steps": [
|
||||
"Set user permissions",
|
||||
"Configure user access levels"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user