我正在使用的應用程序需要爲2種不同類型的用戶單獨登錄。我們需要「客戶」和「業務」所有者能夠註冊。多註冊,使用django-allauth的註冊表格
對於「企業」所有者所有我需要做的是設置布爾user.is_business
到True
我已經使用ACCOUNT_SIGNUP_FORM_CLASS
用一個單獨的類,設置布爾爲true,並且用得好好的。 但是,然後客戶端登錄不起作用了。
有沒有辦法爲不同的用戶創建一個單獨的註冊視圖?
我曾嘗試以下
class BusinessUserRegistrationView(FormView):
form_class = BusinessSignupForm
template_name = 'allauth/account/signup.html'
view_name = 'organisersignup'
success_url = reverse_lazy(view_name)
organisersignup = BusinessUserRegistrationView.as_view()
而且形式
class BusinessSignupForm(BaseSignupForm):
password1 = SetPasswordField(label=_("Password"))
password2 = PasswordField(label=_("Password (again)"))
confirmation_key = forms.CharField(max_length=40,
required=False,
widget=forms.HiddenInput())
def __init__(self, *args, **kwargs):
super(BusinessSignupForm, self).__init__(*args, **kwargs)
if not app_settings.SIGNUP_PASSWORD_VERIFICATION:
del self.fields["password2"]
def clean(self):
super(BusinessSignupForm, self).clean()
if app_settings.SIGNUP_PASSWORD_VERIFICATION \
and "password1" in self.cleaned_data \
and "password2" in self.cleaned_data:
if self.cleaned_data["password1"] \
!= self.cleaned_data["password2"]:
raise forms.ValidationError(_("You must type the same password"
" each time."))
return self.cleaned_data
def save(self, request):
adapter = get_adapter()
user = adapter.new_user(request)
user.is_business = True
adapter.save_user(request, user, self)
self.custom_signup(request, user)
setup_user_email(request, user, [])
return user
而在urls.py
url(r'^organiser/$', 'authentication.views.organisersignup', name='organisersignup'),
的問題是,不知何故,布爾is_business是永遠設置爲True。 從節目中,我可以保存,但保存的東西從來不是一個始終是客戶的業務。 BusinessSignupForm是在allauth表單中找到的SignUpForm的副本。
我在做什麼錯?