allow go to admin dashboard only to supersusers

This commit is contained in:
Cayo Puigdefabregas 2023-10-09 11:28:06 +02:00
parent 8c0cb82e90
commit 0d88f03355
1 changed files with 8 additions and 1 deletions

View File

@ -17,8 +17,8 @@ from django.views.generic.edit import DeleteView, FormView
from django.views.generic.list import ListView
from django.contrib.auth import views as auth_views
from django.contrib.auth.models import User
from django.shortcuts import redirect
from .forms import LoginForm
logger = logging.getLogger(__name__)
@ -41,6 +41,13 @@ class UserDashboardView(LoginRequiredMixin, TemplateView):
class AdminDashboardView(UserDashboardView):
template_name = "idhub/admin_dashboard.html"
def get(self, request):
if not request.user.is_superuser:
url = reverse_lazy('idhub:user_dashboard')
return redirect(url)
return super().get(request)
class LoginView(auth_views.LoginView):
template_name = 'auth/login.html'