sivanr
sivanr

Reputation: 487

Allauth verified user

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?"

Upvotes: 5

Views: 2195

Answers (1)

pennersr
pennersr

Reputation: 6531

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:

from allauth.account.models import EmailAddress

if EmailAddress.objects.filter(user=request.user, verified=True).exists():
    ...

The above works regardless how many email addresses the user has setup...

Upvotes: 14

Related Questions