diff --git a/backend/app/api/api_v1/api.py b/backend/app/api/api_v1/api.py new file mode 100644 index 0000000000..3b305b6c45 --- /dev/null +++ b/backend/app/api/api_v1/api.py @@ -0,0 +1,2 @@ +from app.api.api_v1.endpoints import login +api_router.include_router(login.router, prefix="/auth", tags=["auth"]) diff --git a/backend/app/api/api_v1/endpoints/login.py b/backend/app/api/api_v1/endpoints/login.py new file mode 100644 index 0000000000..3eac6d71a9 --- /dev/null +++ b/backend/app/api/api_v1/endpoints/login.py @@ -0,0 +1,15 @@ +from fastapi import APIRouter, HTTPException +from pydantic import BaseModel + +router = APIRouter() + +class LoginRequest(BaseModel): + email: str + password: str + is_verified: bool = False + +@router.post("/login") +def login(request: LoginRequest): + if not request.is_verified: + raise HTTPException(status_code=403, detail="Email not verified") + return {"message": f"Welcome {request.email}"} diff --git a/backend/app/tests/test_login.py b/backend/app/tests/test_login.py new file mode 100644 index 0000000000..c30c6abe47 --- /dev/null +++ b/backend/app/tests/test_login.py @@ -0,0 +1,22 @@ +from fastapi.testclient import TestClient +from app.main import app + +client = TestClient(app) + +def test_login_verified_user(): + response = client.post("/auth/login", json={ + "email": "test@example.com", + "password": "secure", + "is_verified": True + }) + assert response.status_code == 200 + assert "Welcome" in response.json()["message"] + +def test_login_unverified_user(): + response = client.post("/auth/login", json={ + "email": "test@example.com", + "password": "secure", + "is_verified": False + }) + assert response.status_code == 403 + assert response.json()["detail"] == "Email not verified"