0

我有以下登录视图:

@axes_dispatch
@check_recaptcha_login
def loginpage(request, credentials: dict = None):
    form = RegisterForm()
    attempts_list = get_user_attempts(request, credentials)

    attempt_count = max(
        (
                attempts.aggregate(Sum("failures_since_start"))[
                    "failures_since_start__sum"
                ]
                or 0
        )
        for attempts in attempts_list
    )
    #print(attempt_count)

    attempt_count = attempt_count

    context = {'attempt_count': attempt_count}


    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = authenticate(request, username=username, password=password)

        if user is not None:

            if user.is_active and attempt_count < 3:
                login(request, user)
                return redirect('home')

            elif user.is_active and request.recaptcha_is_valid:
                login(request, user)
                return redirect('home')

            if not user.is_active:
                messages.error(request, 'Account for this User has not been Activated.')
        else:
            messages.error(request, 'Username or Password is Incorrect.')

    #print(context)
    return render(request, 'login.html', context)

但是我现在使用 django 两个因素身份验证视图,并希望在我的上面的代码中将装饰器和尝试计数代码和上下文以及 if 语句登录尝试(在如果用户不是 None :) 与以下基于 LoginView 类的视图集成链接:https ://github.com/Bouke/django-two-factor-auth/blob/master/two_factor/views/core.py

我相信我需要更改自己的登录视图以调用上面链接中的 loginView 并将我的装饰器和上面提到的自定义代码添加到视图中,但不确定如何执行此操作。非常感谢您的帮助。谢谢

4

0 回答 0