Add LoginRequiredMixin mixin for various views

This commit is contained in:
PCoder 2019-02-24 20:13:09 +01:00
parent 0591a186d8
commit c3b8f7b553
2 changed files with 7 additions and 5 deletions

View file

@ -16,5 +16,5 @@ urlpatterns = [
path('logout/', LogOut.as_view(), name="logout"),
path('reset/<str:user>/<str:token>/', ResetRequest.as_view()),
path('reset/', ResetRequest.as_view(), name="reset"),
path('', Index.as_view(), name="index"),
path('', Index.as_view(), name="login_index"),
]

View file

@ -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')