Example #1
0
class EnrolmentStartView(NotFoundOnDisabledFeature,
                         RedirectAlreadyEnrolledMixin, StepsListMixin,
                         TemplateView):
    template_name = 'enrolment/start.html'

    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )

    def dispatch(self, request, *args, **kwargs):
        if request.sso_user:
            if helpers.user_has_company(request.sso_user.session_id):
                return redirect('find-a-buyer')
        return super().dispatch(request, *args, **kwargs)
Example #2
0
class BusinessTypeRoutingView(NotFoundOnDisabledFeature,
                              RedirectAlreadyEnrolledMixin, StepsListMixin,
                              FormView):
    form_class = forms.BusinessType
    template_name = 'enrolment/business-type.html'
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )

    def dispatch(self, *args, **kwargs):
        if not settings.FEATURE_FLAGS['ENROLMENT_SELECT_BUSINESS_ON']:
            return redirect(URL_COMPANIES_HOUSE_ENROLMENT)
        return super().dispatch(*args, **kwargs)

    def form_valid(self, form):
        choice = form.cleaned_data['choice']
        if choice == constants.COMPANIES_HOUSE_COMPANY:
            url = URL_COMPANIES_HOUSE_ENROLMENT
        elif choice == constants.SOLE_TRADER:
            url = URL_SOLE_TRADER_ENROLMENT
        else:
            raise NotImplementedError()
        self.request.session[SESSION_KEY_COMPANY_CHOICE] = choice
        return redirect(url)
    class TestView(views.StepsListMixin, TemplateView):
        template_name = 'directory_components/base.html'

        steps_list_conf = helpers.StepsListConf(
            form_labels_user=[
                views.PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            ],
            form_labels_anon=[
                views.PROGRESS_STEP_LABEL_USER_ACCOUNT,
                views.PROGRESS_STEP_LABEL_PERSONAL_INFO,
            ],
        )
Example #4
0
class ResendVerificationCodeView(NotFoundOnDisabledFeature,
                                 RedirectLoggedInMixin, RestartOnStepSkipped,
                                 ProgressIndicatorMixin, StepsListMixin,
                                 NamedUrlSessionWizardView):

    form_list = (
        (RESEND_VERIFICATION, forms.ResendVerificationCode),
        (VERIFICATION, forms.UserAccountVerification),
    )

    templates = {
        RESEND_VERIFICATION: 'enrolment/user-account-resend-verification.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        FINISHED: 'enrolment/start.html',
    }

    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_anon={
            RESEND_VERIFICATION: 1,
            VERIFICATION: 2
        },
        first_step=RESEND_VERIFICATION,
        # logged in users should not get here
        step_counter_user={},
    )
    steps_list_conf = helpers.StepsListConf(
        form_labels_anon=[
            'Resend verification',
            PROGRESS_STEP_LABEL_VERIFICATION,
        ],
        # logged in users should not get here
        form_labels_user=[],
    )

    def get_template_names(self):
        return [self.templates[self.steps.current]]

    def done(self, form_list, **kwargs):
        cookies = self.get_cleaned_data_for_step(VERIFICATION)['cookies']
        choice = self.request.session.get('company_choice')
        if choice == constants.COMPANIES_HOUSE_COMPANY:
            url = URL_COMPANIES_HOUSE_ENROLMENT
        elif choice == constants.SOLE_TRADER:
            url = URL_SOLE_TRADER_ENROLMENT
        else:
            url = reverse('enrolment-business-type')
        response = redirect(url)
        response.cookies.update(cookies)
        return response

    def render_next_step(self, form, **kwargs):
        response = super().render_next_step(form, **kwargs)
        if form.prefix == RESEND_VERIFICATION:
            email = form.cleaned_data['email']
            verification_code = helpers.regenerate_verification_code(email)
            if verification_code:
                helpers.send_verification_code_email(
                    email=email,
                    verification_code=verification_code,
                    form_url=self.request.path,
                )
        return response

    def get_context_data(self, *args, **kwargs):
        return super().get_context_data(
            verification_missing_url=urls.build_great_url(
                'contact/triage/great-account/verification-missing/'),
            contact_url=urls.build_great_url('contact/domestic/'),
            *args,
            **kwargs)

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == VERIFICATION:
            data = self.get_cleaned_data_for_step(RESEND_VERIFICATION)
            if data:
                form_initial['email'] = data['email']
        return form_initial
Example #5
0
class PreVerifiedEnrolmentView(BaseEnrolmentWizardView):
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[PROGRESS_STEP_LABEL_PERSONAL_INFO],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={PERSONAL_INFO: 1},
        step_counter_anon={
            USER_ACCOUNT: 1,
            VERIFICATION: 2,
            PERSONAL_INFO: 3,
        },
        first_step=USER_ACCOUNT,
    )

    form_list = (
        (USER_ACCOUNT, forms.UserAccount),
        (VERIFICATION, forms.UserAccountVerification),
        (PERSONAL_INFO, forms.PersonalDetails),
    )

    templates = {
        USER_ACCOUNT: 'enrolment/user-account.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        PERSONAL_INFO: 'enrolment/preverified-personal-details.html',
        FINISHED: 'enrolment/success-pre-verified.html',
        FAILURE: 'enrolment/failure-pre-verified.html',
    }

    def get(self, *args, **kwargs):
        key = self.request.GET.get('key')
        if key:
            data = helpers.retrieve_preverified_company(key)
            if data:
                self.request.session[SESSION_KEY_COMPANY_DATA] = data
                self.request.session[SESSION_KEY_ENROL_KEY] = key
                self.request.session.save()
            else:
                return redirect(reverse('enrolment-start'))
        if self.steps.current == PERSONAL_INFO:
            if not self.request.session.get(SESSION_KEY_COMPANY_DATA):
                return redirect(reverse('enrolment-start'))
        return super().get(*args, **kwargs)

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        if self.steps.current == PERSONAL_INFO:
            context['company'] = (
                self.request.session[SESSION_KEY_COMPANY_DATA])
        return context

    def done(self, form_list, **kwargs):
        try:
            self.claim_company(self.serialize_form_list(form_list))
        except HTTPError:
            template_name = self.templates[FAILURE]
        else:
            template_name = self.templates[FINISHED]
        return TemplateResponse(self.request, template_name)

    def claim_company(self, data):
        helpers.claim_company(
            enrolment_key=self.request.session[SESSION_KEY_ENROL_KEY],
            personal_name=f'{data["given_name"]} {data["family_name"]}',
            sso_session_id=self.request.sso_user.session_id,
        )

    def serialize_form_list(self, form_list):
        data = {}
        for form in form_list:
            data.update(form.cleaned_data)
        return data
Example #6
0
class SoleTraderEnrolmentView(CreateCompanyProfileMixin,
                              BaseEnrolmentWizardView):
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={
            COMPANY_SEARCH: 2,
            BUSINESS_INFO: 3,
            PERSONAL_INFO: 4,
        },
        step_counter_anon={
            USER_ACCOUNT: 2,
            VERIFICATION: 3,
            COMPANY_SEARCH: 4,
            BUSINESS_INFO: 4,
            PERSONAL_INFO: 5,
        },
        first_step=USER_ACCOUNT,
    )

    form_list = (
        (USER_ACCOUNT, forms.UserAccount),
        (VERIFICATION, forms.UserAccountVerification),
        (COMPANY_SEARCH, forms.SoleTraderSearch),
        (BUSINESS_INFO, forms.SoleTraderBusinessDetails),
        (PERSONAL_INFO, forms.PersonalDetails),
    )

    templates = {
        USER_ACCOUNT: 'enrolment/user-account.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        COMPANY_SEARCH: 'enrolment/sole-trader-search.html',
        BUSINESS_INFO: 'enrolment/sole-trader-business-details.html',
        PERSONAL_INFO: 'enrolment/sole-trader-personal-details.html',
        FINISHED: 'enrolment/success-sole-trader.html',
    }

    def get_form_initial(self, step):
        form_initial = super().get_form_initial(step)
        if step == BUSINESS_INFO:
            data = self.get_cleaned_data_for_step(COMPANY_SEARCH)
            if data:
                form_initial['address'] = data['address'].replace(', ', '\n')
                form_initial['postal_code'] = data['postal_code']
                form_initial['company_name'] = data['company_name']
        return form_initial

    def done(self, form_list, **kwargs):
        data = self.serialize_form_list(form_list)
        self.create_company_profile(data)
        return TemplateResponse(self.request, self.templates[FINISHED])

    def serialize_form_list(self, form_list):
        return {
            'company_type': 'SOLE_TRADER',
            **super().serialize_form_list(form_list)
        }
Example #7
0
class CompaniesHouseEnrolmentView(CreateCompanyProfileMixin,
                                  BaseEnrolmentWizardView):
    progress_conf = helpers.ProgressIndicatorConf(
        step_counter_user={
            COMPANY_SEARCH: 2,
            BUSINESS_INFO: 2,
            PERSONAL_INFO: 3,
        },
        step_counter_anon={
            USER_ACCOUNT: 2,
            VERIFICATION: 3,
            COMPANY_SEARCH: 4,
            BUSINESS_INFO: 4,
            PERSONAL_INFO: 5,
        },
        first_step=USER_ACCOUNT,
    )
    steps_list_conf = helpers.StepsListConf(
        form_labels_user=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
        form_labels_anon=[
            PROGRESS_STEP_LABEL_BUSINESS_TYPE,
            PROGRESS_STEP_LABEL_USER_ACCOUNT,
            PROGRESS_STEP_LABEL_VERIFICATION,
            PROGRESS_STEP_LABEL_BUSINESS_DETAILS,
            PROGRESS_STEP_LABEL_PERSONAL_INFO,
        ],
    )

    form_list = (
        (USER_ACCOUNT, forms.UserAccount),
        (VERIFICATION, forms.UserAccountVerification),
        (COMPANY_SEARCH, forms.CompaniesHouseSearch),
        (BUSINESS_INFO, forms.CompaniesHouseBusinessDetails),
        (PERSONAL_INFO, forms.PersonalDetails),
    )

    templates = {
        USER_ACCOUNT: 'enrolment/user-account.html',
        VERIFICATION: 'enrolment/user-account-verification.html',
        COMPANY_SEARCH: 'enrolment/companies-house-search.html',
        BUSINESS_INFO: 'enrolment/companies-house-business-details.html',
        PERSONAL_INFO: 'enrolment/companies-house-personal-details.html',
        FINISHED: 'enrolment/success-companies-house.html',
    }

    def get_form_kwargs(self, step=None):
        form_kwargs = super().get_form_kwargs(step=step)
        if step == BUSINESS_INFO:
            previous_data = self.get_cleaned_data_for_step(COMPANY_SEARCH)
            if previous_data:
                form_kwargs['company_data'] = helpers.get_company_profile(
                    number=previous_data['company_number'],
                    session=self.request.session,
                )
                form_kwargs['is_enrolled'] = helpers.get_is_enrolled(
                    company_number=previous_data['company_number'],
                    session=self.request.session,
                )
        elif step == COMPANY_SEARCH:
            form_kwargs['session'] = self.request.session
        return form_kwargs

    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        if self.steps.current == COMPANY_SEARCH:
            context['company_not_found_url'] = urls.build_great_url(
                'contact/triage/great-account/company-not-found/')
        return context

    def serialize_form_list(self, form_list):
        return {
            'company_type': 'COMPANIES_HOUSE',
            **super().serialize_form_list(form_list)
        }

    def done(self, form_list, **kwargs):
        data = self.serialize_form_list(form_list)
        is_enrolled = helpers.get_is_enrolled(
            company_number=data['company_number'],
            session=self.request.session,
        )
        if is_enrolled:
            helpers.request_collaboration(
                company_number=data['company_number'],
                email=self.request.sso_user.email,
                name=f"{data['given_name']} {data['family_name']}",
                form_url=self.request.path,
            )
        else:
            self.create_company_profile(data)
        return TemplateResponse(self.request, self.templates[FINISHED])