From d31c5e7bd116fb7ad21a98bf7e26356cf0fc43d4 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 22 Nov 2022 15:34:26 +0100 Subject: [PATCH 2/2] auth_fc: show warning on password change page if user is linked to FranceConnect (#69989) --- src/authentic2/views.py | 4 ++++ src/authentic2_auth_fc/apps.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 69e58edc..1bf085eb 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -1560,6 +1560,7 @@ class PasswordChangeView(HomeURLMixin, DjPasswordChangeView): if not utils_misc.user_can_change_password(request=request): messages.warning(request, _('Password change is forbidden')) return utils_misc.redirect(request, self.post_change_redirect) + hooks.call_hooks('password_change_view', request=self.request) return super().dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): @@ -1567,6 +1568,9 @@ class PasswordChangeView(HomeURLMixin, DjPasswordChangeView): return utils_misc.redirect(request, self.post_change_redirect) return super().post(request, *args, **kwargs) + def get(self, request, *args, **kwargs): + return super().get(request, *args, **kwargs) + def form_valid(self, form): hooks.call_hooks('event', name='change-password', user=self.request.user, request=self.request) models.PasswordReset.objects.filter(user=self.request.user).delete() diff --git a/src/authentic2_auth_fc/apps.py b/src/authentic2_auth_fc/apps.py index 2a5ef20b..e985fc39 100644 --- a/src/authentic2_auth_fc/apps.py +++ b/src/authentic2_auth_fc/apps.py @@ -115,3 +115,18 @@ class AppConfig(django.apps.AppConfig): if url: return [url] return [] + + def a2_hook_password_change_view(self, request=None, **kwargs): + from django.contrib import messages + from django.utils.translation import gettext as _ + + if request and request.user.is_authenticated and request.user.fc_accounts.exists(): + messages.warning( + request, + _( + '''\ +Watch out, this password is the one from your local account and not the one from the \ +account used through FranceConnect. It will only be useful when you connect \ +with locally and not through FranceConnect.''' + ), + ) -- 2.37.2