I'm using django 1.6 with allauth. I've just enabled the email verification stuff and am looking for the best way to identify if a user has a verified email or not. One interesting thing I encountered and wanted to ask about: I noticed that a user can have several email addresses. Why is it so? this makes the above test a bit more complicated since you have to ask "does the user have at least one verified email address?"
allauth offers a decorator for this:
from allauth.account.decorators import verified_email_required
@verified_email_required
def verified_users_only_view(request):
...
Alternatively, you can use this to check things yourself:
if EmailAddress.objects.filter(user=request.user, verified=True).exists():
...
The above works regardless how many email addresses the user has setup...
来源:https://stackoverflow.com/questions/25621730/allauth-verified-user