Пример #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");
        }
Пример #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdUpdate_Click runs when the Update button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [cnurse]	5/10/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        /// -----------------------------------------------------------------------------
        private void cmdUpdate_Click(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                PortalController.PortalTemplateInfo template = LoadPortalTemplateInfoForSelectedItem();

                try
                {
                    bool   blnChild;
                    string strPortalAlias;
                    string strChildPath  = string.Empty;
                    var    closePopUpStr = string.Empty;

                    var objPortalController = new PortalController();

                    //check template validity
                    var    messages       = new ArrayList();
                    string schemaFilename = Server.MapPath(string.Concat(AppRelativeTemplateSourceDirectory, "portal.template.xsd"));
                    string xmlFilename    = template.TemplateFilePath;
                    var    xval           = new PortalTemplateValidator();
                    if (!xval.Validate(xmlFilename, schemaFilename))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, "", String.Format(Localization.GetString("InvalidTemplate", LocalResourceFile), Path.GetFileName(template.TemplateFilePath)), ModuleMessage.ModuleMessageType.RedError);
                        messages.AddRange(xval.Errors);
                        lstResults.Visible    = true;
                        lstResults.DataSource = messages;
                        lstResults.DataBind();
                        validationPanel.Visible = true;
                        return;
                    }

                    //Set Portal Name
                    txtPortalAlias.Text = txtPortalAlias.Text.ToLowerInvariant();
                    txtPortalAlias.Text = txtPortalAlias.Text.Replace("http://", "");

                    //Validate Portal Name
                    if (!Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                    {
                        blnChild       = true;
                        strPortalAlias = txtPortalAlias.Text;
                    }
                    else
                    {
                        blnChild = (optType.SelectedValue == "C");

                        strPortalAlias = blnChild ? PortalController.GetPortalFolder(txtPortalAlias.Text) : txtPortalAlias.Text;
                    }

                    string message = String.Empty;
                    ModuleMessage.ModuleMessageType messageType = ModuleMessage.ModuleMessageType.RedError;
                    if (!PortalAliasController.ValidateAlias(strPortalAlias, blnChild))
                    {
                        message = Localization.GetString("InvalidName", LocalResourceFile);
                    }

                    //check whether have conflict between tab path and portal alias.
                    var checkTabPath = string.Format("//{0}", strPortalAlias);
                    if (TabController.GetTabByTabPath(PortalSettings.PortalId, checkTabPath, string.Empty) != Null.NullInteger ||
                        TabController.GetTabByTabPath(Null.NullInteger, checkTabPath, string.Empty) != Null.NullInteger)
                    {
                        message = Localization.GetString("DuplicateWithTab", LocalResourceFile);
                    }

                    //Validate Password
                    if (txtPassword.Text != txtConfirm.Text)
                    {
                        if (!String.IsNullOrEmpty(message))
                        {
                            message += "<br/>";
                        }
                        message += Localization.GetString("InvalidPassword", LocalResourceFile);
                    }
                    string strServerPath = Globals.GetAbsoluteServerPath(Request);

                    //Set Portal Alias for Child Portals
                    if (String.IsNullOrEmpty(message))
                    {
                        if (blnChild)
                        {
                            strChildPath = strServerPath + strPortalAlias;

                            if (Directory.Exists(strChildPath))
                            {
                                message = Localization.GetString("ChildExists", LocalResourceFile);
                            }
                            else
                            {
                                if (!Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                                {
                                    strPortalAlias = Globals.GetDomainName(Request, true) + "/" + strPortalAlias;
                                }
                                else
                                {
                                    strPortalAlias = txtPortalAlias.Text;
                                }
                            }
                        }
                    }

                    //Get Home Directory
                    string homeDir = txtHomeDirectory.Text != @"Portals/[PortalID]" ? txtHomeDirectory.Text : "";

                    //Validate Home Folder
                    if (!string.IsNullOrEmpty(homeDir))
                    {
                        if (string.IsNullOrEmpty(String.Format("{0}\\{1}\\", Globals.ApplicationMapPath, homeDir).Replace("/", "\\")))
                        {
                            message = Localization.GetString("InvalidHomeFolder", LocalResourceFile);
                        }
                        if (homeDir.Contains("admin") || homeDir.Contains("DesktopModules") || homeDir.ToLowerInvariant() == "portals/")
                        {
                            message = Localization.GetString("InvalidHomeFolder", LocalResourceFile);
                        }
                    }

                    //Validate Portal Alias
                    if (!string.IsNullOrEmpty(strPortalAlias))
                    {
                        PortalAliasInfo portalAlias = PortalAliasController.GetPortalAliasLookup(strPortalAlias.ToLower());
                        if (portalAlias != null)
                        {
                            message = Localization.GetString("DuplicatePortalAlias", LocalResourceFile);
                        }
                    }

                    //Create Portal
                    if (String.IsNullOrEmpty(message))
                    {
                        //Attempt to create the portal
                        UserInfo adminUser = new UserInfo();
                        int      intPortalId;
                        try
                        {
                            if (useCurrent.Checked)
                            {
                                adminUser   = UserInfo;
                                intPortalId = objPortalController.CreatePortal(txtPortalName.Text,
                                                                               adminUser.UserID,
                                                                               txtDescription.Text,
                                                                               txtKeyWords.Text,
                                                                               template,
                                                                               homeDir,
                                                                               strPortalAlias,
                                                                               strServerPath,
                                                                               strChildPath,
                                                                               blnChild);
                            }
                            else
                            {
                                adminUser = new UserInfo
                                {
                                    FirstName   = txtFirstName.Text,
                                    LastName    = txtLastName.Text,
                                    Username    = txtUsername.Text,
                                    DisplayName = txtFirstName.Text + " " + txtLastName.Text,
                                    Email       = txtEmail.Text,
                                    IsSuperUser = false,
                                    Membership  =
                                    {
                                        Approved         = true,
                                        Password         = txtPassword.Text,
                                        PasswordQuestion = txtQuestion.Text,
                                        PasswordAnswer   = txtAnswer.Text
                                    },
                                    Profile =
                                    {
                                        FirstName = txtFirstName.Text,
                                        LastName  = txtLastName.Text
                                    }
                                };

                                intPortalId = objPortalController.CreatePortal(txtPortalName.Text,
                                                                               adminUser,
                                                                               txtDescription.Text,
                                                                               txtKeyWords.Text,
                                                                               template,
                                                                               homeDir,
                                                                               strPortalAlias,
                                                                               strServerPath,
                                                                               strChildPath,
                                                                               blnChild);
                            }
                        }
                        catch (Exception ex)
                        {
                            intPortalId = Null.NullInteger;
                            message     = ex.Message;
                        }
                        if (intPortalId != -1)
                        {
                            //Create a Portal Settings object for the new Portal
                            PortalInfo objPortal   = objPortalController.GetPortal(intPortalId);
                            var        newSettings = new PortalSettings {
                                PortalAlias = new PortalAliasInfo {
                                    HTTPAlias = strPortalAlias
                                }, PortalId = intPortalId, DefaultLanguage = objPortal.DefaultLanguage
                            };
                            string webUrl = Globals.AddHTTP(strPortalAlias);
                            try
                            {
                                if (!Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                                {
                                    message = Mail.SendMail(PortalSettings.Email,
                                                            txtEmail.Text,
                                                            PortalSettings.Email + ";" + Host.HostEmail,
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", adminUser),
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_BODY", adminUser),
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "");
                                }
                                else
                                {
                                    message = Mail.SendMail(Host.HostEmail,
                                                            txtEmail.Text,
                                                            Host.HostEmail,
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", adminUser),
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_BODY", adminUser),
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "");
                                }
                            }
                            catch (Exception exc)
                            {
                                Logger.Error(exc);

                                closePopUpStr = (PortalSettings.EnablePopUps) ? "onclick=\"return " + UrlUtils.ClosePopUp(true, webUrl, true) + "\"" : "";
                                message       = string.Format(Localization.GetString("UnknownSendMail.Error", LocalResourceFile), webUrl, closePopUpStr);
                            }
                            var objEventLog = new EventLogController();
                            objEventLog.AddLog(objPortalController.GetPortal(intPortalId), PortalSettings, UserId, "", EventLogController.EventLogType.PORTAL_CREATED);

                            // mark default language as published if content localization is enabled
                            bool ContentLocalizationEnabled = PortalController.GetPortalSettingAsBoolean("ContentLocalizationEnabled", PortalId, false);
                            if (ContentLocalizationEnabled)
                            {
                                LocaleController lc = new LocaleController();
                                lc.PublishLanguage(intPortalId, objPortal.DefaultLanguage, true);
                            }

                            //Redirect to this new site
                            if (message == Null.NullString)
                            {
                                webUrl = (PortalSettings.EnablePopUps) ? UrlUtils.ClosePopUp(true, webUrl, false) : webUrl;
                                Response.Redirect(webUrl, true);
                            }
                            else
                            {
                                closePopUpStr = (PortalSettings.EnablePopUps) ? "onclick=\"return " + UrlUtils.ClosePopUp(true, webUrl, true) + "\"" : "";
                                message       = string.Format(Localization.GetString("SendMail.Error", LocalResourceFile), message, webUrl, closePopUpStr);
                                messageType   = ModuleMessage.ModuleMessageType.YellowWarning;
                            }
                        }
                    }
                    UI.Skins.Skin.AddModuleMessage(this, "", message, messageType);
                }
                catch (Exception exc) //Module failed to load
                {
                    Exceptions.ProcessModuleLoadException(this, exc);
                }
            }
        }