Skip to content

Commit

Permalink
[#640] Handle anonymous user's access
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed May 27, 2022
1 parent 22473eb commit f0c69d7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/open_inwoner/accounts/views/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.contrib.auth.mixins import UserPassesTestMixin
from django.shortcuts import redirect
from django.urls import reverse
from django.contrib.auth.views import (
PasswordChangeView,
PasswordResetConfirmView,
Expand All @@ -14,7 +16,15 @@

class LogPasswordChangeView(UserPassesTestMixin, LogMixin, PasswordChangeView):
def test_func(self):
return self.request.user.login_type == LoginTypeChoices.default
if self.request.user.is_authenticated:
return self.request.user.login_type == LoginTypeChoices.default
return False

def handle_no_permission(self):
if self.request.user.is_authenticated:
return redirect(reverse("root"))

return super().handle_no_permission()

def form_valid(self, form):
response = super().form_valid(form)
Expand Down

0 comments on commit f0c69d7

Please sign in to comment.