2020-10-17 21:31:55 +02:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.contrib.auth import logout as auth_logout
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
|
|
|
from urllib.parse import quote as urlquote
|
|
|
|
|
|
|
|
|
|
|
|
def login(req):
|
|
|
|
if req.user.is_authenticated:
|
|
|
|
return redirect("mainsite:home")
|
|
|
|
|
|
|
|
if req.method == "GET":
|
|
|
|
reqDict = req.GET
|
|
|
|
elif req.method == "POST":
|
|
|
|
reqDict = req.POST
|
|
|
|
if "next" in reqDict:
|
|
|
|
nextUrl = reqDict["next"]
|
|
|
|
context = {
|
|
|
|
"pass_url": "{}?next={}".format(
|
|
|
|
reverse("gestiojeux_auth:password_login"), urlquote(nextUrl, safe="")
|
|
|
|
),
|
|
|
|
"cas_url": "{}?next={}".format(
|
|
|
|
reverse("gestiojeux_auth:cas_ng_login"), urlquote(nextUrl, safe="")
|
|
|
|
),
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
context = {
|
|
|
|
"pass_url": reverse("gestiojeux_auth:password_login"),
|
|
|
|
"cas_url": reverse("gestiojeux_auth:cas_ng_login"),
|
|
|
|
}
|
|
|
|
|
2020-10-22 19:24:16 +02:00
|
|
|
return render(req, "login_switch.html", context=context)
|
2020-10-17 21:31:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def logout(req):
|
|
|
|
CAS_BACKEND_NAME = "django_cas_ng.backends.CASBackend"
|
|
|
|
if req.session["_auth_user_backend"] != CAS_BACKEND_NAME:
|
|
|
|
auth_logout(req)
|
|
|
|
return redirect("mainsite:home")
|
|
|
|
return redirect("gestiojeux_auth:cas_ng_logout")
|
|
|
|
|