我有一个创建新用户的视图AccountRegister
。每次我在注册表中输入值时,如果用户已注册电子邮件,则向用户发送验证电子邮件;如果用户已注册电话,则向用户发送验证令牌,如果用户已注册,则向用户发送验证令牌既。注册成功后,用户将被重定向到令牌验证页面。要验证令牌,我需要从TokenVerificationView
访问该用户。如何通过请求发送用户?如何从TokenVerificationView
访问同一用户?
class AccountRegister(CreateView):
model = User
form_class = forms.RegisterForm
template_name = 'account/signup.html'
success_url = reverse_lazy('account:verification')
def form_valid(self, form):
self.user = form.save(self.request)
if self.user.email:
send_email_confirmation(self.request, self.user)
if self.user.phone:
device = self.user.verificationdevice_set.create(
unverified_phone=self.user.phone)
device.generate_challenge()
message = _("Verification Token sent to {phone}")
message = message.format(phone=self.user.phone)
messages.add_message(self.request, messages.SUCCESS, message)
return super().form_valid(form)