我一直在尝试使用自定义表单和视图来实现带有qrcode的django-otp。问题是我有点不明白我的实现是否正确。由于文档指出向已通过 OTP 验证的用户添加了一个属性,因此我实际上无法正确设置。已使用 Microsoft Authenticator 应用程序通过 QR 码设置为用户创建了已确认的 TOTP 设备。request.user.is_verified()
我能够成功实施默认的管理站点 OTP 验证,没有任何问题。以下是自定义实现的文件。
网址.py
from django.conf.urls import url
from account.views import AccountLoginView, AccountHomeView, AccountLogoutView
urlpatterns = [
url(r'^login/$', AccountLoginView.as_view(), name='account-login',),
url(r'^home/$', AccountHomeView.as_view(), name='account-home',),
url(r'^logout/$', AccountLogoutView.as_view(), name='account-logout',)
]
Run Code Online (Sandbox Code Playgroud)
视图.py
from django.contrib.auth import authenticate, login as auth_login
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
from django_otp.forms import OTPAuthenticationForm
class AccountLoginView(FormView):
template_name = 'login.html'
form_class = OTPAuthenticationForm
success_url = '/account/home/'
def form_invalid(self, form):
return super().form_invalid(form)
def form_valid(self, …Run Code Online (Sandbox Code Playgroud)