Django/Userena允许注册

2024-03-29 09:00:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我在想最好的办法。我使用Userena作为我的项目的基础。我想加载一个团队名册上的数据库或保持一个文本文件的名册和用户注册前,网站应该检查用户是否在名册上。如果没有,那么他们将无法注册。你知道吗


Tags: 项目数据库网站检查用户团队基础用户注册文本文件
1条回答
网友
1楼 · 发布于 2024-03-29 09:00:05

在用户ena.forms是报名表。我将扩展表单验证中正在实现的三个干净方法之一。这些是干净的用户名,干净的电子邮件和干净的。你知道吗

例如,下面是clean\u email方法。它已经检查电子邮件是否已经被使用。我会维护一个包含有效电子邮件的花名册表。因此,您可以添加另一层检查。我会把它放在第一个下面。你知道吗

def clean_email(self):
    """ Validate that the e-mail address is unique. """
    if User.objects.filter(email__iexact=self.cleaned_data['email']):
        raise forms.ValidationError(_('This email is already in use. Please supply a different email.'))
    return self.cleaned_data['email']

与检查电子邮件是否被其他用户使用相比。对于花名册,如果在花名册表中找不到,我们将提出错误。你知道吗

def clean_email(self):
    """ Validate that the e-mail address is unique. """
    if User.objects.filter(email__iexact=self.cleaned_data['email']):
        raise forms.ValidationError(_('This email is already in use. Please supply a different email.'))
    if not Roster.objects.filter(email__iexact=self.cleaned_data['email']):
        raise forms.ValidationError(_('You are not able to signup as you are not part of the Roster.'))
    return self.cleaned_data['email']

注意:确保将您的花名册模型导入到您添加支票的任何位置。你知道吗

相关问题 更多 >