Allauth验证的用户 [英] Allauth verified user

查看:60
本文介绍了Allauth验证的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Django 1.6与allauth一起使用。
我刚刚启用了电子邮件验证功能,并且正在寻找识别用户是否拥有已验证电子邮件的最佳方法。
我遇到并想问的一件有趣的事情:我注意到一个用户可以有多个电子邮件地址。为什么会这样呢?这使上面的测试更加复杂,因为您必须问用户是否至少有一个经过验证的电子邮件地址?

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为此提供了一个装饰器:

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

这篇关于Allauth验证的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆