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