你可以在重寫allauth的allauth.socialaccount.forms.SignupForm中執行一些操作,並在註冊過程中檢查域。 Discalmer:這一切都是在沒有測試的情況下編寫的,但是其中的一些內容應該可以工作。
# settings.py
# not necesarry, but it would be a smart way to go instead of hardcoding it
ALLOWED_DOMAIN = 'example.com'
。
# forms.py
from django.conf import settings
from allauth.socialaccount.forms import SignupForm
class MySignupForm(SignupForm):
def clean_email(self):
data = self.cleaned_data['email']
if data.split('@')[1].lower() == settings.ALLOWED_DOMAIN:
raise forms.ValidationError(_(u'domena!'))
return data
在你的URL重寫allauth默認值(之前包括Django的allauth的把這個)
# urls.py
from allauth.socialaccount.views import SignupView
from .forms import MySignupForm
urlpatterns = patterns('',
# ...
url(r"^social/signup/$", SignupView.as_view(form_class=MySignupForm), name="account_signup"),
# ...
)
我不知道對於 「^社會/註冊/ $」,重新檢查。
並在創建自定義適配器後,根據插件文檔中的配置部分將其註冊爲'settings.SOCIALACCOUNT_ADAPTER'。 – Matt
供將來參考我發現我不得不使用'u = sociallogin.user',否則如果用戶之前不存在,我會得到一個錯誤。 –