How can I mark an email as verified in django-allauth?
I'm setting up a website from scrath that has been coded with Django and django-allauth. To create a new superuser from scratch, I need to run this command:
python manage.py createsuperuser
When I try to log in as this user on the website, I see this message:
Verify Your Email Address
We have sent an email to you for verification. Follow the link provided to finalize the signup process. If you do not see the verification email in your main inbox, check your spam folder. Please contact us if you do not receive the verification email within a few minutes.
Let's say that I entered a fake email address or that the website doesn't have working SMTP yet. How do I mark the email address of this user as verified, either from the command-line, or in Python?
Here's the Python code you can use to do this, which you can run in the shell launched by python manage.py shell
:
from django.contrib.auth import get_user_model
from allauth.account.models import EmailAddress
User = get_user_model()
user = User.objects.get(username='admin')
email = EmailAddress.objects.get_for_user(user, 'example@example.com')
email.verified = True
email.save()
You can also use Mailhog or something similar to testing email verification flows.