防止在allauth创建社会帐户 [英] Prevent social account creation in allauth
问题描述
可以在allauth的某些情况下阻止帐户创建,最好使用pre_social_login信号?
开发部门你可以轻松地做到这一点。在您的设置中:
SOCIALACCOUNT_ADAPTER ='my.adapter.MySocialAccountAdapter'
pre>
然后从django使用此adapter.py:
来自allauth.socialaccount.adapter import的http import HttpResponse
来自allauth.exceptions的DefaultSocialAccountAdapter
导入ImmediateHttpResponse
class MySocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login self,request,sociallogin)
raise ImmediateHttpResponse(HttpResponse('closed for the day'))
或者,从您的
pre_social_login
信号引发类似的异常(尽管我不喜欢这种方法 - 请参阅 https://github.com/pennersr/django-allauth/blob/master/allauth/ socialaccount / adapter.py#L15Is it possible to prevent account creation under certain circumstances in allauth, preferably using the pre_social_login signal?
解决方案With the current development branch you can easily do this. In your settings:
SOCIALACCOUNT_ADAPTER = 'my.adapter.MySocialAccountAdapter'
Then use this adapter.py:
from django.http import HttpResponse from allauth.socialaccount.adapter import DefaultSocialAccountAdapter from allauth.exceptions import ImmediateHttpResponse class MySocialAccountAdapter(DefaultSocialAccountAdapter): def pre_social_login(self, request, sociallogin): raise ImmediateHttpResponse(HttpResponse('Closed for the day'))
Alternatively, raise a similar exception from your
pre_social_login
signal (although I do not prefer that approach -- see documentation notes over at https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/adapter.py#L15这篇关于防止在allauth创建社会帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!