1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-13 15:05:30 +00:00

2fa failed_attempt (#5288)

This commit is contained in:
欢乐马 2022-11-11 15:35:23 +08:00 committed by GitHub
parent 132169105a
commit 16a686d2fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -291,6 +291,9 @@ class OTPAuthenticationFormMixin(object):
class AuthenticationTokenForm(OTPAuthenticationFormMixin, Form):
SESSION_KEY_TWO_FACTOR_FAILED_ATTEMPT = '2fa-failed-attempt'
otp_token = forms.IntegerField(label=_("Token"), min_value=1,
max_value=int('9' * totp_digits()))
remember_me = forms.BooleanField(required=False)
@ -304,7 +307,15 @@ class AuthenticationTokenForm(OTPAuthenticationFormMixin, Form):
"""
super(AuthenticationTokenForm, self).__init__(**kwargs)
self.user = user
self.request = request
def clean(self):
self.clean_otp(self.user)
return self.cleaned_data
def is_valid(self):
ret = super(Form, self).is_valid()
if not ret:
failed_attempt = self.request.session.get(self.SESSION_KEY_TWO_FACTOR_FAILED_ATTEMPT, 0)
self.request.session[self.SESSION_KEY_TWO_FACTOR_FAILED_ATTEMPT] = failed_attempt + 1
return ret