Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 219
sivanr Avatar asked Sep 02 '14 10:09

sivanr


1 Answers

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...

like image 108
pennersr Avatar answered Sep 26 '22 16:09

pennersr