我有这个网址:(Django 2.0)
re_path('auth/(?P<code_>[a-zA-Z0-9]{12})/(?P<email_>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', homePageView.autenticate, name='autenticate'),
在我的views.py中:
class homePageView(TemplateView):
template_name = 'index.html'
def autenticate(self, email_, code_):
try:
user = Usuario.objects.get(email=email_,activated_code=code_)
code = user.two_factors_auth_code
if (not user.two_factors_auth) and (code == code_) and (len(code) == 12):
user.next_login = True
user.save()
return redirect('home')
except Usuario.DoesNotExist:
return redirect('home')
我希望我可以在我的认证方法中登录用户,但我的函数中没有请求参数。
¿ 如何将我的 autenticate 功能转换为另一个?
class homePageView(TemplateView):
template_name = 'index.html'
def autenticate(self, request, email_, code_):
try:
user = Usuario.objects.get(email=email_,activated_code=code_)
code = user.two_factors_auth_code
if (not user.two_factors_auth) and (code == code_) and (len(code) == 12):
user.next_login = True
user.save()
####################
login(request,user)
####################
return redirect('home')
except Usuario.DoesNotExist:
return redirect('home')