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:
parent
132169105a
commit
16a686d2fd
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user