Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何禁用django allauth创建新帐户,但仍然允许现有用户登录?_Python_Django_Authentication_Django Allauth - Fatal编程技术网

Python 如何禁用django allauth创建新帐户,但仍然允许现有用户登录?

Python 如何禁用django allauth创建新帐户,但仍然允许现有用户登录?,python,django,authentication,django-allauth,Python,Django,Authentication,Django Allauth,我们已经运行了一段时间的站点,该站点使用以下任何一种进行身份验证: 传统的基于电子邮件的注册 谷歌登录 Twitter登录 Facebook登录 。。。但是现在我们想阻止任何人创建新帐户,同时仍然允许以前使用这些方法创建帐户的人能够登录。有没有一个环境可以让我们这样做?我不清楚是否有人会允许我们配置它 与django allauth相关的当前设置为: INSTALLED_APPS = ( 'django.contrib.auth', ... 'allauth',

我们已经运行了一段时间的站点,该站点使用以下任何一种进行身份验证:

  • 传统的基于电子邮件的注册
  • 谷歌登录
  • Twitter登录
  • Facebook登录
。。。但是现在我们想阻止任何人创建新帐户,同时仍然允许以前使用这些方法创建帐户的人能够登录。有没有一个环境可以让我们这样做?我不清楚是否有人会允许我们配置它

与django allauth相关的当前设置为:

INSTALLED_APPS = (
    'django.contrib.auth',
    ...
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.twitter',
    ...
)

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
)

SOCIALACCOUNT_PROVIDERS = {
    'google': {'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile'],
               'AUTH_PARAMS': {'access_type': 'online'}},
    'facebook': {'SCOPE': ['email',]},
}

LOGIN_REDIRECT_URL = '/'

ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
SOCIALACCOUNT_AUTO_SIGNUP = True
医生给我修了这个。为了添加更多细节,我创建了一个文件
mysite/account\u adapter.py
,其中包含:

from allauth.account.adapter import DefaultAccountAdapter

class NoNewUsersAccountAdapter(DefaultAccountAdapter):

    def is_open_for_signup(self, request):
        """
        Checks whether or not the site is open for signups.

        Next to simply returning True/False you can also intervene the
        regular flow by raising an ImmediateHttpResponse

        (Comment reproduced from the overridden method.)
        """
        return False
然后将其添加到
mysite/settings.py

ACCOUNT_ADAPTER = 'mysite.account_adapter.NoNewUsersAccountAdapter'

以防这对其他人有帮助。我按照上面的说明操作,但将我的自定义适配器文件命名为
account\u adapter.py
,这似乎是保留名称,因此它给出了
modulenofounderror
。我不得不将其重命名为其他名称,例如
我的帐户\u adapter.py
,然后这就成功了。@curtisp您是否尝试将其放入您的应用程序文件夹,如
mysite/
?好的,thx没有完全阅读答案。我把它和
settings.py
放在同一个文件夹中,但我只是试着用
views.py
等将它移动到
app
文件夹中,它的工作名为
account\u adapter.py