Django Интеграция существующего кода в общее представление на основе классов с двухфакторным аутентификатором
У меня есть следующий вид входа:
@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 two factor auth views, и хотел бы интегрировать декораторы и код подсчета попыток, контекст и if statement login attempts (under if user is not None:) в моем вышеприведенном коде с представлением на основе класса LoginView из следующей ссылки: https://github.com/Bouke/django-two-factor-auth/blob/master/two_factor/views/core.py
Я считаю, что мне нужно изменить мое собственное представление входа в систему, чтобы вызвать loginView, который находится по ссылке выше, и добавить мои декораторы и мой пользовательский код, упомянутый выше, в представление, но не уверен, как это сделать. За помощь буду очень признателен. Спасибо