Viewing File: /usr/local/cpanel/whostmgr/docroot/templates/gsw/initial_setup/views/createAccountController.js

/*
 * views/createAccountController.js                 Copyright 2022 cPanel, L.L.C.
 *                                                           All rights reserved.
 * copyright@cpanel.net                                         http://cpanel.net
 * This code is subject to the cPanel license. Unauthorized copying is prohibited
 */

/* eslint-env amd */

define([
    "angular",
    "cjt/util/locale",
    "app/services/setupService",
], function(angular, LOCALE) {

    "use strict";

    function CreateAccountController(PAGE, $location, setupService, $scope, $window, $q) {
        this.PAGE = PAGE;
        this.$location = $location;
        this.setupService = setupService;
        this.$scope = $scope;
        this.$window = $window;
        this.$q = $q;

        if (!PAGE.has_accepted_legal_agreements) {
            $location.path("/legal");
        }

        if (PAGE.has_completed_initial_setup || PAGE.is_dnsonly || !PAGE.requested_initial_website) {
            this.exit();
        }
    }

    CreateAccountController.$inject = [
        "PAGE",
        "$location",
        "setupService",
        "$scope",
        "$window",
        "$q",
    ];

    /**
     * Creates the account via the API.
     * @method submit
     */
    CreateAccountController.prototype.create = function() {
        var self = this;

        if (self.isSubmitting) {
            return;
        }

        if (!self.PAGE.requested_initial_website) {
            self.exit();
            return;
        }

        self.isSubmitting = true;

        var errorKeys = [];

        return self.setupService.initialWebsite(self.email)
            .catch(function(error) {
                errorKeys.push("initial_website");
            })
            .then(function() {
                if (errorKeys.length) {
                    return self.setupService.saveErrors(errorKeys);
                }
            }).finally(function() {
                self.exit();
            });
    };

    /**
     * Exits the initial setup assistant and drops them to the next step.
     * @method exit
     */
    CreateAccountController.prototype.exit = function() {
        this.$window.location.href = "../initial_setup_wizard1_do";
    };

    CreateAccountController.prototype.requested = function() {
        return this.PAGE.requested_initial_website;
    };

    angular
        .module("whm.initialSetup.createAccountController", [
            "whm.initialSetup.setupService",
        ])
        .controller("createAccountController", CreateAccountController);

    return CreateAccountController;
});
Back to Directory File Manager