I want the user to be able to change their email address. The user will change his email address, after which a confirmation email address will be sent to this address, after the user clicks the link, he will change his email address in the database.
I know that django-generic-confirm deals with similar confirmations, but I would like to try to do it myself.
To change the email address, my code will look like this:
User.objects.get(username=username).update(email=request.POST['email'])
And to send an email to this address, I would:
if 'Change Email' in request.POST.values():
from django.core.mail import send_mail
send_mail(
'Confirm email change',
'Click this **link** to confirm your change of email',
'from@example.com',
[request.POST['email']]
)
How can I postpone an email change in db until the user confirms his email? And how do I create a link that activates email for this process? Thank.