Skip to content

Commit

Permalink
Add login required mixin, redirect users from frontpage if they have …
Browse files Browse the repository at this point in the history
…already authenticated
  • Loading branch information
michaeljcollinsuk committed Mar 28, 2024
1 parent 2f4df93 commit e5fda7c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions controlpanel/frontend/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
from django.views.generic import TemplateView

# First-party/Local
from controlpanel.oidc import oauth
from controlpanel.oidc import OIDCLoginRequiredMixin, oauth


class FrontPageView(TemplateView):
class FrontPageView(OIDCLoginRequiredMixin, TemplateView):
http_method_names = ["get", "post"]
template_name = "frontpage.html"
# TODO bypass when user has already authenticated with UserPassesTestMixin

def _get_code_challenge(self):
code_verifier = generate_token(64)
digest = hashlib.sha256(code_verifier.encode()).digest()
return base64.urlsafe_b64encode(digest).rstrip(b"=").decode()
def get(self, request, *args, **kwargs):
if self.request.user.justice_email:
return HttpResponseRedirect(reverse("index"))
return super().get(request, *args, **kwargs)

def post(self, request):
code_challenge = self._get_code_challenge()
Expand All @@ -35,8 +34,13 @@ def post(self, request):
code_challenge=code_challenge,
)

def _get_code_challenge(self):
code_verifier = generate_token(64)
digest = hashlib.sha256(code_verifier.encode()).digest()
return base64.urlsafe_b64encode(digest).rstrip(b"=").decode()


class EntraIdAuthView(View):
class EntraIdAuthView(OIDCLoginRequiredMixin, View):
http_method_names = ["get"]

def _authorize_token(self):
Expand Down

0 comments on commit e5fda7c

Please sign in to comment.