Allauth verified user

五迷三道 提交于 2019-12-07 06:13:50

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!