我正在创建逻辑,以确认电子邮件验证新的电子邮件地址。 但是发送验证邮件后,我不知道如何保存新的电子邮件地址。我需要将新电子邮件地址保存在某个地方,以便在用户检查验证电子邮件时可以将其保存。 验证逻辑通常如何工作?
我当前的代码是这样的
views.py
def change_email(request):
if request.method == 'POST':
form = ChangeEmailForm(request.POST)
if form.is_valid():
# send the verification email here while creating a token
...
to_email = form.cleaned_data.get('new_email')
email = EmailMessage(subject, message, to=[to_email],)
email.send()
return HttpResponseRedirect...
def verify_email(request, uid64, token):
# user verify the new email address when checking the verification email here but how I can save the new email address the user input
如何保存用户输入的新电子邮件地址或将新电子邮件地址值保存在表单上,以便以后保存?
答案 0 :(得分:0)
扩展用户模型以添加其他字段“ new_email”,然后在发送电子邮件之前将其保存。
def change_email(request):
if request.method == 'POST':
form1 = ChangeEmailForm(request.POST)
if form1.is_valid():
request.user.new_email = form.cleaned_data['new_email']
request.user.save()
...