防止在allauth创建社会帐户 [英] Prevent social account creation in allauth

查看:103
本文介绍了防止在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#L15


Is 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆