Multiple registrations, registration forms using django-allauth

The application I'm working on requires a separate login for two different types of users. We need the owners of "customers" and "business" in order to be able to register.

For the owner of "business", all I have to do is set boolean user.is_businesstoTrue

I used ACCOUNT_SIGNUP_FORM_CLASSwith a separate class that sets the boolean to true and works like a charm. But then the client login no longer works.

Is there a way to create a separate registration type for another user?

I tried the following

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()

And form

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

And in urls.py

url(r'^organiser/$', 'authentication.views.organisersignup', name='organisersignup'),

, , is_business True. , , , , . BusinessSignupForm - SignUpForm, allauth.

?

+4
2

, allauth.

:

class BusinessSignupForm(SignupForm):
    def save(self, request):
        user = super(BusinessSignupForm, self).save(request)
        user.is_organizer = True
        user.save()
        return user

class BusinessUserRegistrationView(SignupView):
    template_name = 'allauth/account/signup-organizer.html'
    form_class = BusinessSignupForm
    redirect_field_name = 'next'
    view_name = 'organisersignup'
    success_url = None

    def get_context_data(self, **kwargs):
        ret = super(BusinessUserRegistrationView, self).get_context_data(**kwargs)
        ret.update(self.kwargs)
        return ret

organisersignup = BusinessUserRegistrationView.as_view()

 <form id="signup_form" method="post" action="{% url 'organisersignup' %}">
      {% csrf_token %}
      {% bootstrap_form form %}
 </form>

, .

Django == 1.8.10 django-allauth == 0.24.1

+5

user.is_business = True BusinessProfile. , , PartnerProfile, ClientProfile, SupplierProfile .. , .

: django-allauth

+1

All Articles