From 63ca4f8fab590a0cc010697eb654e1e75bdb90f7 Mon Sep 17 00:00:00 2001 From: Bai Date: Fri, 24 Feb 2023 14:23:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=A4=E8=AF=81MFA?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=AC=A1=E6=95=B0=E6=B8=85=E7=A9=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/mixins.py | 1 + apps/authentication/views/mfa.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index 5355d79bd..14e5fd35f 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -225,6 +225,7 @@ class MFAMixin: self.request.session['auth_mfa_time'] = time.time() self.request.session['auth_mfa_required'] = 0 self.request.session['auth_mfa_type'] = mfa_type + MFABlockUtils(self.request.user.username, self.get_request_ip()).clean_failed_count() def clean_mfa_mark(self): keys = ['auth_mfa', 'auth_mfa_time', 'auth_mfa_required', 'auth_mfa_type'] diff --git a/apps/authentication/views/mfa.py b/apps/authentication/views/mfa.py index fd8b80e32..c297a3261 100644 --- a/apps/authentication/views/mfa.py +++ b/apps/authentication/views/mfa.py @@ -32,11 +32,14 @@ class UserLoginMFAView(mixins.AuthMixin, FormView): return super().get(*args, **kwargs) def form_valid(self, form): + from users.utils import MFABlockUtils code = form.cleaned_data.get('code') mfa_type = form.cleaned_data.get('mfa_type') try: self._do_check_user_mfa(code, mfa_type) + user, ip = self.get_user_from_session(), self.get_request_ip() + MFABlockUtils(user.username, ip).clean_failed_count() return redirect_to_guard_view('mfa_ok') except (errors.MFAFailedError, errors.BlockMFAError) as e: form.add_error('code', e.msg)