我正在开发的应用程序需要两种不同类型的用户单独登录。我们需要“客户”和“企业”所有者能够注册。
对于“企业”所有者,我需要做的就是设置布尔值user.is_business
to 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 的副本。
我究竟做错了什么?