Projet

Général

Profil

0002-auth_fc-show-warning-on-password-change-page-if-user.patch

Benjamin Dauvergne, 22 novembre 2022 15:37

Télécharger (2,47 ko)

Voir les différences:

Subject: [PATCH 2/3] 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(+)
src/authentic2/views.py
1560 1560
        if not utils_misc.user_can_change_password(request=request):
1561 1561
            messages.warning(request, _('Password change is forbidden'))
1562 1562
            return utils_misc.redirect(request, self.post_change_redirect)
1563
        hooks.call_hooks('password_change_view', request=self.request)
1563 1564
        return super().dispatch(request, *args, **kwargs)
1564 1565

  
1565 1566
    def post(self, request, *args, **kwargs):
......
1567 1568
            return utils_misc.redirect(request, self.post_change_redirect)
1568 1569
        return super().post(request, *args, **kwargs)
1569 1570

  
1571
    def get(self, request, *args, **kwargs):
1572
        return super().get(request, *args, **kwargs)
1573

  
1570 1574
    def form_valid(self, form):
1571 1575
        hooks.call_hooks('event', name='change-password', user=self.request.user, request=self.request)
1572 1576
        models.PasswordReset.objects.filter(user=self.request.user).delete()
src/authentic2_auth_fc/apps.py
115 115
        if url:
116 116
            return [url]
117 117
        return []
118

  
119
    def a2_hook_password_change_view(self, request=None, **kwargs):
120
        from django.contrib import messages
121
        from django.utils.translation import gettext as _
122

  
123
        if request and request.user.is_authenticated and request.user.fc_accounts.exists():
124
            messages.warning(
125
                request,
126
                _(
127
                    '''\
128
Watch out, this password is the one from your local account and not the one from the \
129
account used through FranceConnect. It will only be useful when you connect \
130
with locally and not through FranceConnect.'''
131
                ),
132
            )
118
-