chore: Small cleanup
This commit is contained in:
parent
3681bed05d
commit
129e43252a
6 changed files with 29 additions and 24 deletions
|
@ -11,4 +11,4 @@ class ApiKeyAdmin(admin.ModelAdmin):
|
||||||
def save_model(self, request, obj, form, change):
|
def save_model(self, request, obj, form, change):
|
||||||
if not change:
|
if not change:
|
||||||
obj.initialFill()
|
obj.initialFill()
|
||||||
super(ApiKeyAdmin, self).save_model(request, obj, form, change)
|
super().save_model(request, obj, form, change)
|
||||||
|
|
|
@ -37,7 +37,7 @@ class ApiKey(models.Model):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def keyId(self):
|
def keyId(self):
|
||||||
return self.id
|
return self.pk
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def displayValue(self):
|
def displayValue(self):
|
||||||
|
|
|
@ -4,8 +4,6 @@ Django settings for the bocal project
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.contrib.messages import constants as messages
|
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from loadcredential import Credentials
|
from loadcredential import Credentials
|
||||||
|
|
||||||
|
|
|
@ -95,12 +95,12 @@ def evalRhostsPrivileges(user):
|
||||||
|
|
||||||
@requireCasUser
|
@requireCasUser
|
||||||
def logout(user):
|
def logout(user):
|
||||||
stripCasPrivileges()
|
stripCasPrivileges(user)
|
||||||
|
|
||||||
|
|
||||||
def forceReevalRhosts(fct):
|
def forceReevalRhosts(fct):
|
||||||
def wrap(req, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
evalRhostsPrivileges(req.user)
|
evalRhostsPrivileges(request.user)
|
||||||
return fct(req, *args, **kwargs)
|
return fct(request, *args, **kwargs)
|
||||||
|
|
||||||
return wrap
|
return wrap
|
||||||
|
|
|
@ -2,26 +2,33 @@ from urllib.parse import quote as urlquote
|
||||||
|
|
||||||
from django.contrib.auth import logout as auth_logout
|
from django.contrib.auth import logout as auth_logout
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.http import HttpRequest
|
||||||
|
from django.http.response import Http404
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
def login(req):
|
def login(request: HttpRequest):
|
||||||
if req.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
return redirect("homepage")
|
return redirect("homepage")
|
||||||
|
|
||||||
if req.method == "GET":
|
match request.method:
|
||||||
reqDict = req.GET
|
case "GET":
|
||||||
elif req.method == "POST":
|
data = request.GET
|
||||||
reqDict = req.POST
|
case "POST":
|
||||||
if "next" in reqDict:
|
data = request.POST
|
||||||
nextUrl = reqDict["next"]
|
case _:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
next = data.get("next")
|
||||||
|
|
||||||
|
if next is not None:
|
||||||
context = {
|
context = {
|
||||||
"pass_url": "{}?next={}".format(
|
"pass_url": "{}?next={}".format(
|
||||||
reverse("password_login"), urlquote(nextUrl, safe="")
|
reverse("password_login"), urlquote(next, safe="")
|
||||||
),
|
),
|
||||||
"cas_url": "{}?next={}".format(
|
"cas_url": "{}?next={}".format(
|
||||||
reverse("cas_ng_login"), urlquote(nextUrl, safe="")
|
reverse("cas_ng_login"), urlquote(next, safe="")
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
@ -30,13 +37,13 @@ def login(req):
|
||||||
"cas_url": reverse("cas_ng_login"),
|
"cas_url": reverse("cas_ng_login"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(req, "mainsite/login.html", context=context)
|
return render(request, "mainsite/login.html", context=context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def logout(req):
|
def logout(request: HttpRequest):
|
||||||
CAS_BACKEND_NAME = "django_cas_ng.backends.CASBackend"
|
if request.session["_auth_user_backend"] != "django_cas_ng.backends.CASBackend":
|
||||||
if req.session["_auth_user_backend"] != CAS_BACKEND_NAME:
|
auth_logout(request)
|
||||||
auth_logout(req)
|
|
||||||
return redirect("homepage")
|
return redirect("homepage")
|
||||||
|
|
||||||
return redirect("cas_ng_logout")
|
return redirect("cas_ng_logout")
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SiteConfiguration(SingletonModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Configuration du site"
|
return "Configuration du site"
|
||||||
|
|
||||||
class Meta:
|
class Meta: # pyright: ignore
|
||||||
verbose_name = "Configuration du site"
|
verbose_name = "Configuration du site"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue