Prevent social account creation in allauth

丶灬走出姿态 提交于 2019-12-12 09:43:51

问题


Is it possible to prevent account creation under certain circumstances in allauth, preferably using the pre_social_login signal?


回答1:


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



来源:https://stackoverflow.com/questions/13646805/prevent-social-account-creation-in-allauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!