From c3b8f7b553314e28ee76efe580cacf74010eeb6c Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 24 Feb 2019 20:13:09 +0100 Subject: [PATCH] Add LoginRequiredMixin mixin for various views --- dal/urls.py | 2 +- dal/views.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dal/urls.py b/dal/urls.py index f977499..b5f4a3a 100644 --- a/dal/urls.py +++ b/dal/urls.py @@ -16,5 +16,5 @@ urlpatterns = [ path('logout/', LogOut.as_view(), name="logout"), path('reset///', ResetRequest.as_view()), path('reset/', ResetRequest.as_view(), name="reset"), - path('', Index.as_view(), name="index"), + path('', Index.as_view(), name="login_index"), ] \ No newline at end of file diff --git a/dal/views.py b/dal/views.py index 334a197..1b055fa 100644 --- a/dal/views.py +++ b/dal/views.py @@ -27,6 +27,7 @@ import ldap import ldap.modlist as modlist from django.conf import settings +from django.contrib.auth.mixins import LoginRequiredMixin class Index(FormView): @@ -93,7 +94,7 @@ class Register(View): return render(request, 'usercreated.html', { 'user': username } ) -class ChangeData(View): +class ChangeData(LoginRequiredMixin, View): # provide the form for the change request def get(self, request): urlname = 'change_data' @@ -166,7 +167,8 @@ class ChangeData(View): return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': msg } ) -class ResetPassword(View): +class ResetPassword(LoginRequiredMixin, View): + login_url = reverse_lazy('login_index') def get(self, request): return render(request, 'resetpassword.html') @@ -339,7 +341,7 @@ class ResetRequest(View): # The logged in user can change the password here -class ChangePassword(View): +class ChangePassword(LoginRequiredMixin, View): # Presents the page for a logged in user def get(self, request): @@ -389,7 +391,7 @@ class ChangePassword(View): # Deletes an account -class DeleteAccount(View): +class DeleteAccount(LoginRequiredMixin, View): # Show the basic form for deleting an account def get(self, request): return render(request, 'deleteaccount.html')