gpt4 book ai didi

django - 默认创建非事件用户(is_active default False)

转载 作者:行者123 更新时间:2023-12-04 13:06:05 25 4
gpt4 key购买 nike

我在我的网站上使用了 Facebook 身份验证 omab / django-social-auth

我想将用户重定向到另一个网站,让他们填写详细信息。所以我想让用户在他们第一次使用他们的 Facebook 帐户进行身份验证时处于非事件状态,然后在他们完成表单后我将他们保存为事件用户。

我在我的环境下操作了 django/contrib/auth/models.py,就像 is_active 字段一样默认=False;但他们被保存为事件用户
但结果还是一样,即使我从管理面板添加了一个普通用户。有什么我想念的吗?

class User(models.Model):
"""
Users within the Django authentication system are represented by this
model.

Username and password are required. Other fields are optional.
"""
username = models.CharField(_('username'), max_length=30, unique=True,
help_text=_('Required. 30 characters or fewer. Letters, numbers and '
'@/./+/-/_ characters'))
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
password = models.CharField(_('password'), max_length=128)
is_staff = models.BooleanField(_('staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.'))
is_active = models.BooleanField(_('active'), default=False,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.'))
is_superuser = models.BooleanField(_('superuser status'), default=False,
help_text=_('Designates that this user has all permissions without '
'explicitly assigning them.'))
last_login = models.DateTimeField(_('last login'), default=timezone.now)
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
groups = models.ManyToManyField(Group, verbose_name=_('groups'),
blank=True, help_text=_('The groups this user belongs to. A user will '
'get all permissions granted to each of '
'his/her group.'))
user_permissions = models.ManyToManyField(Permission,
verbose_name=_('user permissions'), blank=True,
help_text='Specific permissions for this user.')
objects = UserManager()


def create_user(self, username, email=None, password=None):
"""
Creates and saves a User with the given username, email and password.
"""
now = timezone.now()
if not username:
raise ValueError('The given username must be set')
email = UserManager.normalize_email(email)
user = self.model(username=username, email=email,
is_staff=False, is_active=False, is_superuser=False,
last_login=now, date_joined=now)

user.set_password(password)
user.save(using=self._db)
return user

最佳答案

  • 避免修改内置函数。有更好的方法来做事。
  • signals .信号很棒。
  • 在这种情况下,我会附加到 django.contrib.auth.models.User 的 pre_save 信号。 ,并手动更正 is_active模型实例的属性(如果对象是新的)。
  • 通过这种方式,您可以添加一些逻辑以确保您正确地将用户标记为不活跃。
  • 因为在管理员中添加的用户可能应该处于事件状态,如果管理员将它们标记为事件状态。
  • 关于django - 默认创建非事件用户(is_active default False),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15122895/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com