Django allauth创建复制用户?

ioekq8ef  于 2023-08-08  发布在  Go
关注(0)|答案(1)|浏览(82)

我有一个从AbstractUser继承的customerUser,如果用户注册电子邮件aaaa@gmail.com,然后第二次,他试图注册与谷歌登录和相同的电子邮件(aaa@gmail.com)
Django-Alluth是否创建了一个重复的用户,如果是的话,我该如何避免这种情况?

from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import CustomUser

class CustomUserCreationForm(UserCreationForm):
    class Meta(UserCreationForm.Meta):
        model = CustomUser
        fields = (
            "username",
            "email",
            "age",
        )  # ne
        email = {"required": True}

class CustomUserChangeForm(UserChangeForm):
    class Meta:
        model = CustomUser
        fields = (
            "username",
            "email",
            "age",
        )  # ne
        email = {"required": True}

class CustomUser(AbstractUser):
    age = models.PositiveIntegerField(null=True, blank=True)
    email = models.EmailField(blank=False, null=False)

字符串

cuxqih21

cuxqih211#

您可以使电子邮件字段唯一以避免这种情况

email = models.EmailField(blank=False, null=False, unique=True)

字符串

相关问题