public async signup()

in src/components/users/signup/ko/runtime/signup.ts [144:222]


    public async signup(): Promise<void> {
        const captchaIsRequired = this.requireHipCaptcha();

        const validationGroup = {
            email: this.email,
            password: this.password,
            passwordConfirmation: this.passwordConfirmation,
            firstName: this.firstName,
            lastName: this.lastName
        };

        if (captchaIsRequired) {
            if (!this.setCaptchaValidation) {
                this.logger.trackEvent("CaptchaValidation", { message: "Captcha failed to initialize." });
                dispatchErrors(this.eventManager, ErrorSources.signup, [ValidationMessages.captchaNotInitialized]);
                return;
            }

            validationGroup["captcha"] = this.captcha;
            this.setCaptchaValidation(this.captcha);
        }

        if (this.termsEnabled() && this.isConsentRequired()) {
            validationGroup["consented"] = this.consented;
        }

        const result = validation.group(validationGroup);

        const clientErrors = result();

        if (clientErrors.length > 0) {
            result.showAllMessages();
            dispatchErrors(this.eventManager, ErrorSources.signup, clientErrors);
            return;
        }

        const mapiSignupData: MapiSignupRequest = {
            email: this.email(),
            firstName: this.firstName(),
            lastName: this.lastName(),
            password: this.password(),
            confirmation: "signup",
            appType: Constants.AppType
        };

        try {
            this.working(true);
            dispatchErrors(this.eventManager, ErrorSources.signup, []);

            if (captchaIsRequired) {
                const captchaRequestData = this.captchaData();
                const createSignupRequest: SignupRequest = {
                    challenge: captchaRequestData.challenge,
                    solution: captchaRequestData.solution?.solution,
                    flowId: captchaRequestData.solution?.flowId,
                    token: captchaRequestData.solution?.token,
                    type: captchaRequestData.solution?.type,
                    signupData: mapiSignupData
                };

                await this.backendService.sendSignupRequest(createSignupRequest);
            }
            else {
                await this.usersService.createSignupRequest(mapiSignupData);
            }

            this.isUserRequested(true);
        }
        catch (error) {
            if (captchaIsRequired) {
                await this.refreshCaptcha();
            }

            parseAndDispatchError(this.eventManager, ErrorSources.signup, error, this.logger, Constants.genericHttpRequestError);
        }
        finally {
            this.working(false);
        }
    }