From e924e182345a55cee1da44b06a0b21e007b0afa3 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Sat, 23 May 2020 12:04:09 +0200 Subject: [PATCH] Implement name display in login views --- core/views/auth.py | 7 +++++++ templates/backend/auth/otp_selector.html | 2 +- templates/backend/auth/otp_verifier.html | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/views/auth.py b/core/views/auth.py index 64fcba7..f2cd87e 100644 --- a/core/views/auth.py +++ b/core/views/auth.py @@ -38,6 +38,7 @@ class LoginView(FormView): self.request.session["otpsession"] = str(session.uuid) self.request.session["next"] = self.request.GET.get("next", "dashboard") return redirect("otpselector") + messages.error(self.request, "The credentials you entered are invalid. Please try again.") return super().form_invalid(form) class OTPSelectorView(FormView): @@ -72,6 +73,9 @@ class OTPSelectorView(FormView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["title"] = "Two-Factor Authentication" + + user = LoginSession.objects.get(uuid=self.request.session["otpsession"]).user + context["first_name"] = user.profile.get_internal_name return context class OTPValidatorView(FormView): @@ -125,6 +129,9 @@ class OTPValidatorView(FormView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["title"] = "Two-Factor Authentication" + + user, provider = self.validate_session(self.request) + context["first_name"] = user.profile.get_internal_name return context class LogoutView(View): diff --git a/templates/backend/auth/otp_selector.html b/templates/backend/auth/otp_selector.html index 256c182..482c964 100644 --- a/templates/backend/auth/otp_selector.html +++ b/templates/backend/auth/otp_selector.html @@ -4,7 +4,7 @@

- Welcome back {{ request.user.first_name }}, + Welcome back {{ first_name }}, Please select your Two-Factor Authentication provider

{% bootstrap_messages %}
diff --git a/templates/backend/auth/otp_verifier.html b/templates/backend/auth/otp_verifier.html index 5cad949..5e9cf9a 100644 --- a/templates/backend/auth/otp_verifier.html +++ b/templates/backend/auth/otp_verifier.html @@ -4,7 +4,7 @@