Update web/core/views.py

This commit is contained in:
Joshua Laymon 2026-01-10 00:05:14 +00:00
parent c0acced574
commit 1ada8e4fa2

View File

@ -14,6 +14,7 @@ from django.urls import reverse
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from .models_user import SearchHistory, ViewedIllustration from .models_user import SearchHistory, ViewedIllustration
from django.conf import settings
from .forms import ImportForm, EntryForm from .forms import ImportForm, EntryForm
from .models import Entry from .models import Entry
@ -59,8 +60,16 @@ def is_admin(user):
def login_view(request): def login_view(request):
# Already logged into Django
if request.user.is_authenticated: if request.user.is_authenticated:
return redirect("search") return redirect("search")
# Pangolin + Authentik already authenticated the user at the proxy layer
# → immediately initiate OIDC login
if request.method == "GET":
return redirect("oidc_authentication_init")
# Fallback: local username/password login (optional)
ctx = {} ctx = {}
if request.method == "POST": if request.method == "POST":
u = request.POST.get("username") u = request.POST.get("username")
@ -70,8 +79,8 @@ def login_view(request):
login(request, user) login(request, user)
return redirect("search") return redirect("search")
ctx["error"] = "Invalid credentials" ctx["error"] = "Invalid credentials"
return render(request, "login.html", ctx)
return render(request, "login.html", ctx)
def entry_context(entry, result_ids): def entry_context(entry, result_ids):
""" """