您可以在注册过程中覆盖 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
在您的网址中覆盖 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"),
# ...
)
我不确定“^social/signup/$”,重新检查一下。