Add capture_login_admin view
This fixes a redirection loop causing an authenticated user which is *not* staff accessing /admin to be loop-redirected between /admin -> /admin/login -> /accounts/login Also include some hideous basic page to show a message. This should not be a problem; a non-admin user accessing /admin deserves hurting their eyes.
This commit is contained in:
parent
83658010f0
commit
44e26bb8de
2 changed files with 52 additions and 0 deletions
32
allauth_ens/templates/allauth_ens/simple_message.html
Normal file
32
allauth_ens/templates/allauth_ens/simple_message.html
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
{% load i18n static %}
|
||||||
|
{% load account allauth_ens %}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Error{% if request.site.name %} · {{ request.site.name }}{% endif %}</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: #ffffd8;
|
||||||
|
}
|
||||||
|
#messagebox {
|
||||||
|
max-width: 500px;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
margin-top: 50px;
|
||||||
|
background-color: white;
|
||||||
|
border: 2px solid black;
|
||||||
|
border-radius: 15px;
|
||||||
|
padding: 25px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="messagebox">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,5 +1,8 @@
|
||||||
import django
|
import django
|
||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
if django.VERSION >= (1, 10):
|
if django.VERSION >= (1, 10):
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
@ -23,3 +26,20 @@ class CaptureLogout(RedirectView):
|
||||||
|
|
||||||
|
|
||||||
capture_logout = CaptureLogout.as_view()
|
capture_logout = CaptureLogout.as_view()
|
||||||
|
|
||||||
|
|
||||||
|
def capture_login_admin(request):
|
||||||
|
""" Redirect the user to allauth login page if they are not logged in, or
|
||||||
|
fails and display a message if they are logged in *but* are not
|
||||||
|
administrators """
|
||||||
|
|
||||||
|
if admin.site.has_permission(request):
|
||||||
|
return capture_login(request)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'message': ("The account you're authenticated with is not an "
|
||||||
|
"administrator account."),
|
||||||
|
}
|
||||||
|
return render(request,
|
||||||
|
"allauth_ens/simple_message.html",
|
||||||
|
context=context)
|
||||||
|
|
Loading…
Reference in a new issue