Show error message if not allowed to access admin page.

This commit is contained in:
Tiberiu Chibici 2018-12-29 17:18:54 +02:00
parent 8eca3dc7a9
commit 05ecb6a493
2 changed files with 9 additions and 7 deletions

View File

@ -4,8 +4,16 @@
{% block body %}
<div class="container">
<h1>Admin settings</h1>
{% if not request.user.is_authenticated or not request.user.is_superuser %}
<div class="alert alert-danger" role="alert">
You must be an administrator to access this page!
</div>
{% else %}
{% crispy form %}
{% endif %}
</div>
{% endblock body %}

View File

@ -24,12 +24,6 @@ class AdminSettingsView(LoginRequiredMixin, FormView):
template_name = 'YtManagerApp/settings_admin.html'
success_url = reverse_lazy('home')
def get(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_superuser:
return HttpResponseForbidden()
return super().get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
if not request.user.is_authenticated or not request.user.is_superuser:
return HttpResponseForbidden()