Example #1
0
        private void CreateSite(PortalConfig portal, InstallConfig installConfig)
        {
            var domain = "";

            if ((HttpContext.Current != null))
            {
                domain = Globals.GetDomainName(HttpContext.Current.Request, true).ToLowerInvariant().Replace("/install/launchautoinstall", "").Replace("/install", "").Replace("/runinstall", "");
            }

            var portalController = new PortalController();
            var serverPath       = Globals.ApplicationMapPath + "\\";

            //Get the Portal Alias
            var portalAlias = domain;

            if (portal.PortAliases.Count > 0)
            {
                portalAlias = portal.PortAliases[0];
            }

            //Verify that portal alias is not present
            if (PortalAliasController.GetPortalAliasLookup(portalAlias.ToLower()) != null)
            {
                string description = Localization.Localization.GetString("SkipCreatingSite", LocalInstallResourceFile);
                Details = string.Format(description, portalAlias);
                return;
            }

            //Create default email
            var email = portal.AdminEmail;

            if (string.IsNullOrEmpty(email))
            {
                email = "admin@" + domain.Replace("www.", "");
                //Remove any domain subfolder information ( if it exists )
                if (email.IndexOf("/") != -1)
                {
                    email = email.Substring(0, email.IndexOf("/"));
                }
            }

            //install LP if installing in a different language
            string culture = installConfig.InstallCulture;

            if (!culture.Equals("en-us", StringComparison.InvariantCultureIgnoreCase))
            {
                string installFolder = HttpContext.Current.Server.MapPath("~/Install/language");
                Upgrade.InstallPackage(installFolder + "\\installlanguage.resources", "Language", false);
            }

            var      template = Upgrade.FindBestTemplate(portal.TemplateFileName);
            UserInfo userInfo;

            if (!String.IsNullOrEmpty(portal.AdminUserName))
            {
                userInfo = Upgrade.CreateUserInfo(portal.AdminFirstName, portal.AdminLastName, portal.AdminUserName, portal.AdminPassword, email);
            }
            else
            {
                userInfo = Upgrade.CreateUserInfo(installConfig.SuperUser.FirstName, installConfig.SuperUser.LastName, installConfig.SuperUser.UserName, installConfig.SuperUser.Password, installConfig.SuperUser.Email);
            }

            var childPath = string.Empty;

            if (portal.IsChild)
            {
                childPath = portalAlias.Substring(portalAlias.LastIndexOf("/") + 1);
            }

            //Create Portal
            var portalId = portalController.CreatePortal(portal.PortalName,
                                                         userInfo,
                                                         portal.Description,
                                                         portal.Keywords,
                                                         template,
                                                         portal.HomeDirectory,
                                                         portalAlias,
                                                         serverPath,
                                                         serverPath + childPath,
                                                         portal.IsChild);

            if (portalId > -1)
            {
                foreach (var alias in portal.PortAliases)
                {
                    portalController.AddPortalAlias(portalId, alias);
                }
            }

            //remove en-US from portal if installing in a different language
            if (!culture.Equals("en-us", StringComparison.InvariantCultureIgnoreCase))
            {
                var locale = LocaleController.Instance.GetLocale("en-US");
                Localization.Localization.RemoveLanguageFromPortal(portalId, locale.LanguageId);
            }

            //Log user in to site
            var loginStatus = UserLoginStatus.LOGIN_FAILURE;

            UserController.UserLogin(portalId, userInfo.Username, installConfig.SuperUser.Password, "", "", "", ref loginStatus, false);

            InstallController.Instance.RemoveFromInstallConfig("//dotnetnuke/superuser/password");
        }