Update web/core/views.py
This commit is contained in:
parent
73da1bcf85
commit
2b6a8820e0
@ -53,6 +53,33 @@ EXPECTED_HEADERS = [
|
|||||||
"Date Edited",
|
"Date Edited",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def login_view(request):
|
||||||
|
# Already logged into Django
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
return redirect("search")
|
||||||
|
|
||||||
|
# IMPORTANT:
|
||||||
|
# Only auto-initiate OIDC on a *direct* visit to /login/
|
||||||
|
# Never during the OIDC callback flow
|
||||||
|
if (
|
||||||
|
request.method == "GET"
|
||||||
|
and not request.path.startswith("/oidc/")
|
||||||
|
):
|
||||||
|
return redirect("oidc_authentication_init")
|
||||||
|
|
||||||
|
# Local login fallback (optional)
|
||||||
|
ctx = {}
|
||||||
|
if request.method == "POST":
|
||||||
|
u = request.POST.get("username")
|
||||||
|
p = request.POST.get("password")
|
||||||
|
user = authenticate(request, username=u, password=p)
|
||||||
|
if user:
|
||||||
|
login(request, user)
|
||||||
|
return redirect("search")
|
||||||
|
ctx["error"] = "Invalid credentials"
|
||||||
|
|
||||||
|
return render(request, "login.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
def is_admin(user):
|
def is_admin(user):
|
||||||
return user.is_superuser or user.is_staff
|
return user.is_superuser or user.is_staff
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user