Mar*_*air 9 python authentication django django-allauth
我们已经运行了一段时间的网站,django-allauth用于使用以下任何一种身份验证:
...但现在我们想要阻止任何人创建一个新帐户,同时仍允许之前使用这些方法创建帐户的人能够登录.是否有设置可以让我们这样做?我不清楚任何这些记录的设置将允许我们配置它.
与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
Run Code Online (Sandbox Code Playgroud)
Mar*_*air 22
rnevius的问题与我有关.为了添加更多细节,我创建了一个mysite/account_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
Run Code Online (Sandbox Code Playgroud)
然后将其添加到mysite/settings.py:
ACCOUNT_ADAPTER = 'mysite.account_adapter.NoNewUsersAccountAdapter'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3466 次 |
| 最近记录: |