feat: Update endpoint login
This commit is contained in:
parent
6ee6f691c5
commit
23bb58eeed
@ -1,25 +1,48 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from core.auth import get_current_user_dummy
|
||||
from core.database import fake_users_db
|
||||
import uuid
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/login")
|
||||
async def login_demo(
|
||||
username: str = "demo",
|
||||
password: str = "password"
|
||||
class StudentCreate(BaseModel):
|
||||
name: str
|
||||
email: str
|
||||
age: int
|
||||
grade: str
|
||||
|
||||
@router.post("/api/v1/endpoint")
|
||||
async def create_student(
|
||||
student: StudentCreate
|
||||
):
|
||||
"""Demo login endpoint"""
|
||||
user = fake_users_db.get(username)
|
||||
if not user or user["password"] != password:
|
||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
||||
"""Create new student record"""
|
||||
student_id = str(uuid.uuid4())
|
||||
|
||||
# Check if email already exists
|
||||
for existing_student in fake_users_db.values():
|
||||
if existing_student.get("email") == student.email:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Student with this email already exists"
|
||||
)
|
||||
|
||||
student_data = {
|
||||
"id": student_id,
|
||||
"name": student.name,
|
||||
"email": student.email,
|
||||
"age": student.age,
|
||||
"grade": student.grade,
|
||||
"created_at": "2024-01-01T00:00:00" # Demo timestamp
|
||||
}
|
||||
|
||||
fake_users_db[student_id] = student_data
|
||||
|
||||
return {
|
||||
"message": "Login successful (demo)",
|
||||
"user": username,
|
||||
"token": "dummy_jwt_token_123",
|
||||
"features": {
|
||||
"rate_limit": 100,
|
||||
"expires_in": 3600
|
||||
}
|
||||
}
|
||||
"message": "Student created successfully",
|
||||
"student_id": student_id,
|
||||
"data": student_data,
|
||||
"next_steps": [
|
||||
"Complete student profile",
|
||||
"Upload required documents"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user