如何将Django-axes与Django-two-factor-auth集成?

时间:2019-05-07 09:02:51

标签: django python-3.x

我正在尝试将Django轴与django-two-factor-auth集成,但是在身份验证表单中发布第一步时遇到错误:

AxesBackend requires a request as an argument to authenticate

我猜我应该从Django.contrib.auth覆盖AuthenticationForm,因为这是调用authenticate的地方,但不确定要作为请求传递什么:

class LoginForm(AuthenticationForm):
    class Meta:
    fields = ('username', 'password')

def clean(self):
    username = self.cleaned_data.get('username')
    password = self.cleaned_data.get('password')

    if username is not None and password:
        self.user_cache = authenticate(self.request, username=username, password=password)
        if self.user_cache is None:
            raise self.get_invalid_login_error()
        else:
            self.confirm_login_allowed(self.user_cache)

    return self.cleaned_data

我也没有任何运气就覆盖了视图和多种方法。任何帮助,将不胜感激。让我知道是否需要更多信息。

0 个答案:

没有答案