Adding LDAP support

This commit is contained in:
Ian Roddis committed 2026-07-19 12:02:41 -03:00
1 parent d60ad42f0c
commit f2b99089ea
17 files changed
+541 -23

No files matched your search

+10 -5
View File
@@ -4,10 +4,9 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.core.config import settings
from app.core.database import get_db
from app.crud import user as user_crud
from app.deps import get_current_web_user
from app.models.user import User
from app.services.auth import issue_token_pair
from app.services.auth import authenticate, issue_token_pair
from app.web.templates import templates
router = APIRouter(include_in_schema=False)
@@ -35,7 +34,9 @@ async def dashboard(
@router.get("/login", response_class=HTMLResponse)
async def login_page(request: Request):
return templates.TemplateResponse(request, "login.html", {})
return templates.TemplateResponse(
request, "login.html", {"ldap_enabled": settings.ldap_enabled}
)
@router.post("/login")
@@ -45,13 +46,17 @@ async def login_submit(
password: str = Form(...),
db: AsyncSession = Depends(get_db),
):
user = await user_crud.authenticate(db, email, password)
user = await authenticate(db, email, password)
if user is None:
# Re-render the form with an error (HTMX swaps the form partial).
return templates.TemplateResponse(
request,
"login.html",
{"error": "Incorrect email or password", "email": email},
{
"error": "Incorrect email or password",
"email": email,
"ldap_enabled": settings.ldap_enabled,
},
status_code=status.HTTP_401_UNAUTHORIZED,
)
access, _ = await issue_token_pair(db, user)