Пример #1
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Wizard_NextButtonClickruns when the next Button is clicked.  It provides
 ///	a mechanism for cancelling the page change if certain conditions aren't met.
 /// </summary>
 /// <history>
 /// 	[cnurse]	12/04/2006	created
 /// </history>
 protected void Wizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
 {
     switch (e.CurrentStepIndex)
     {
         case 1: //Templates
             //Before we leave Page 1, the user must have selected a Portal
             if (lstTemplate.SelectedIndex == -1)
             {
                 if (chkTemplate.Checked)
                 {
                     e.Cancel = true;
                     lblTemplateMessage.Text = Localization.GetString("TemplateRequired", this.LocalResourceFile);
                 }
             }
             else
             {
                 //Check Template Validity before proceeding
                 string schemaFilename = Server.MapPath("admin/Portal/portal.template.xsd");
                 string xmlFilename = Globals.HostMapPath + lstTemplate.SelectedItem.Text + ".template";
                 PortalTemplateValidator xval = new PortalTemplateValidator();
                 if (! (xval.Validate(xmlFilename, schemaFilename)))
                 {
                     string strMessage = Localization.GetString("InvalidTemplate", this.LocalResourceFile);
                     lblTemplateMessage.Text = string.Format(strMessage, lstTemplate.SelectedItem.Text + ".template");
                     //Cancel Page move if invalid template
                     e.Cancel = true;
                 }
             }
             break;
     }
 }
        /// -----------------------------------------------------------------------------
        /// <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)
            {
                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 = Globals.HostMapPath + cboTemplate.SelectedItem.Text + ".template";
                    var xval = new PortalTemplateValidator();
                    if (!xval.Validate(xmlFilename, schemaFilename))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, "", String.Format(Localization.GetString("InvalidTemplate", LocalResourceFile), cboTemplate.SelectedItem.Text + ".template"), ModuleMessage.ModuleMessageType.RedError);
                        messages.AddRange(xval.Errors);
                        lstResults.Visible = true;
                        lstResults.DataSource = messages;
                        lstResults.DataBind();
                        return;
                    }

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

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

                        strPortalAlias = blnChild ? txtPortalName.Text.Substring(txtPortalName.Text.LastIndexOf("/") + 1) : txtPortalName.Text;
                    }

                    string message = String.Empty;
                    ModuleMessage.ModuleMessageType messageType = ModuleMessage.ModuleMessageType.RedError;
                    if (!PortalAliasController.ValidateAlias(strPortalAlias, blnChild))
                    {
                        message = Localization.GetString("InvalidName", 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 = txtPortalName.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))
                    {
                        string strTemplateFile = cboTemplate.SelectedItem.Text + ".template";

                        //Attempt to create the portal
                        var objAdminUser = new UserInfo();
                        int intPortalId;
                        try
                        {
                            objAdminUser.FirstName = txtFirstName.Text;
                            objAdminUser.LastName = txtLastName.Text;
                            objAdminUser.Username = txtUsername.Text;
                            objAdminUser.DisplayName = txtFirstName.Text + " " + txtLastName.Text;
                            objAdminUser.Email = txtEmail.Text;
                            objAdminUser.IsSuperUser = false;

                            objAdminUser.Membership.Approved = true;
                            objAdminUser.Membership.Password = txtPassword.Text;
                            objAdminUser.Membership.PasswordQuestion = txtQuestion.Text;
                            objAdminUser.Membership.PasswordAnswer = txtAnswer.Text;

                            objAdminUser.Profile.FirstName = txtFirstName.Text;
                            objAdminUser.Profile.LastName = txtLastName.Text;
                            intPortalId = objPortalController.CreatePortal(txtTitle.Text,
                                                                           objAdminUser,
                                                                           txtDescription.Text,
                                                                           txtKeyWords.Text,
                                                                           Globals.HostMapPath,
                                                                           strTemplateFile,
                                                                           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", objAdminUser),
                                                               Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_BODY", objAdminUser),
                                                               "",
                                                               "",
                                                               "",
                                                               "",
                                                               "",
                                                               "");
                                }
                                else
                                {
                                    message = Mail.SendMail(Host.HostEmail,
                                                               txtEmail.Text,
                                                               Host.HostEmail,
                                                               Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", objAdminUser),
                                                               Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_BODY", objAdminUser),
                                                               "",
                                                               "",
                                                               "",
                                                               "",
                                                               "",
                                                               "");
                                }
                            }
                            catch (Exception exc)
                            {
                                DnnLog.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);

                            //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);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// cmdUpdate_Click runs when the Update button is clicked
        /// </summary>
        /// <history>
        /// 	[cnurse]	5/10/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        protected void cmdUpdate_Click( Object sender, EventArgs e )
        {
            if( Page.IsValid )
            {
                try
                {
                    bool blnChild;
                    string strMessage = String.Empty;
                    string strPortalAlias;
                    int intCounter;
                    string strServerPath;
                    
                    string strChildPath = String.Empty;

                    PortalController objPortalController = new PortalController();
                    PortalSecurity objSecurity = new PortalSecurity();

                    // check template validity
                    ArrayList messages = new ArrayList();
                    string schemaFilename = Server.MapPath( "admin/Portal/portal.template.xsd" );
                    string xmlFilename = Globals.HostMapPath + cboTemplate.SelectedItem.Text + ".template";
                    PortalTemplateValidator xval = new PortalTemplateValidator();
                    if( ! xval.Validate( xmlFilename, schemaFilename ) )
                    {
                        strMessage = Localization.GetString( "InvalidTemplate", this.LocalResourceFile );
                        lblMessage.Text = string.Format( strMessage, cboTemplate.SelectedItem.Text + ".template" );
                        messages.AddRange( xval.Errors );
                        lstResults.Visible = true;
                        lstResults.DataSource = messages;
                        lstResults.DataBind();
                        return;
                    }

                    //Set Portal Name
                    txtPortalName.Text = txtPortalName.Text.ToLower();
                    txtPortalName.Text = txtPortalName.Text.Replace("http://", "");

                    //Validate Portal Name
                    if( PortalSettings.ActiveTab.ParentId != PortalSettings.SuperTabId )
                    {
                        blnChild = true;

                        // child portal
                        for( intCounter = 1; intCounter <= txtPortalName.Text.Length; intCounter++ )
                        {
                            if( "abcdefghijklmnopqrstuvwxyz0123456789-".IndexOf(txtPortalName.Text.Substring(intCounter, 1 )) == 0 )
                            {
                                strMessage += "<br>" + Localization.GetString( "InvalidName", this.LocalResourceFile );
                            }
                        }

                        strPortalAlias = txtPortalName.Text;
                    }
                    else
                    {
                        blnChild = optType.SelectedValue == "C";

                        if( blnChild )
                        {
                            strPortalAlias = txtPortalName.Text.Substring(txtPortalName.Text.LastIndexOf("/") + 1);
                        }
                        else
                        {
                            strPortalAlias = txtPortalName.Text;
                        }

                        string strValidChars = "abcdefghijklmnopqrstuvwxyz0123456789-";
                        if( ! blnChild )
                        {
                            strValidChars += "./:";
                        }

                        for( intCounter = 1; intCounter <= strPortalAlias.Length; intCounter++ )
                        {
                            if (strValidChars.IndexOf(strPortalAlias.Substring(intCounter - 1, 1)) == 0)
                            {
                                strMessage += "<br>" + Localization.GetString( "InvalidName", this.LocalResourceFile );
                            }
                        }
                    }

                    //Validate Password
                    if( txtPassword.Text != txtConfirm.Text )
                    {
                        strMessage += "<br>" + Localization.GetString( "InvalidPassword", this.LocalResourceFile );
                    }

                    strServerPath = Globals.GetAbsoluteServerPath( Request );

                    //Set Portal Alias for Child Portals
                    if( strMessage == "" )
                    {
                        if( blnChild )
                        {
                            strChildPath = strServerPath + strPortalAlias;

                            if( Directory.Exists( strChildPath ) )
                            {
                                strMessage = Localization.GetString( "ChildExists", this.LocalResourceFile );
                            }
                            else
                            {
                                if( PortalSettings.ActiveTab.ParentId != PortalSettings.SuperTabId )
                                {
                                    strPortalAlias = Globals.GetDomainName( Request ) + "/" + strPortalAlias;
                                }
                                else
                                {
                                    strPortalAlias = txtPortalName.Text;
                                }
                            }
                        }
                    }

                    //Get Home Directory
                    string HomeDir;
                    if( txtHomeDirectory.Text != "Portals/[PortalID]" )
                    {
                        HomeDir = txtHomeDirectory.Text;
                    }
                    else
                    {
                        HomeDir = "";
                    }

                    //Create Portal
                    if( strMessage == "" )
                    {
                        string strTemplateFile = cboTemplate.SelectedItem.Text + ".template";

                        //Attempt to create the portal
                        int intPortalId;
                        try
                        {
                            intPortalId = objPortalController.CreatePortal( txtTitle.Text, txtFirstName.Text, txtLastName.Text, txtUsername.Text, objSecurity.Encrypt( Convert.ToString( Globals.HostSettings["EncryptionKey"] ), txtPassword.Text ), txtEmail.Text, txtDescription.Text, txtKeyWords.Text, Globals.HostMapPath, strTemplateFile, HomeDir, strPortalAlias, strServerPath, strChildPath, blnChild );
                        }
                        catch( Exception ex )
                        {
                            intPortalId = Null.NullInteger;
                            strMessage = ex.Message;
                        }

                        if( intPortalId != - 1 )
                        {
                            // notification
                            UserInfo objUser = UserController.GetUserByName( intPortalId, txtUsername.Text, false );

                            //Create a Portal Settings object for the new Portal
                            PortalSettings newSettings = new PortalSettings();
                            newSettings.PortalAlias = new PortalAliasInfo();
                            newSettings.PortalAlias.HTTPAlias = strPortalAlias;
                            newSettings.PortalId = intPortalId;
                            string webUrl = Globals.AddHTTP( strPortalAlias );

                            try
                            {
                                if( PortalSettings.ActiveTab.ParentId != PortalSettings.SuperTabId )
                                {
                                    Mail.SendMail( PortalSettings.Email, txtEmail.Text, PortalSettings.Email + ";" + Convert.ToString( PortalSettings.HostSettings["HostEmail"] ), Localization.GetSystemMessage( newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", objUser ), Localization.GetSystemMessage( newSettings, "EMAIL_PORTAL_SIGNUP_BODY", objUser ), "", "", "", "", "", "" );
                                }
                                else
                                {
                                    Mail.SendMail( Convert.ToString( PortalSettings.HostSettings["HostEmail"] ), txtEmail.Text, Convert.ToString( PortalSettings.HostSettings["HostEmail"] ), Localization.GetSystemMessage( newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", objUser ), Localization.GetSystemMessage( newSettings, "EMAIL_PORTAL_SIGNUP_BODY", objUser ), "", "", "", "", "", "" );
                                }
                            }
                            catch( Exception )
                            {
                                strMessage = string.Format( Localization.GetString( "SendMail.Error", this.LocalResourceFile ), webUrl, null );
                            }

                            EventLogController objEventLog = new EventLogController();
                            objEventLog.AddLog( objPortalController.GetPortal( intPortalId ), PortalSettings, UserId, "", EventLogController.EventLogType.PORTAL_CREATED );

                            // Redirect to this new site
                            if( strMessage == Null.NullString )
                            {
                                Response.Redirect( webUrl, true );
                            }
                        }
                    }

                    lblMessage.Text = "<br>" + strMessage + "<br><br>";
                }
                catch( Exception exc ) //Module failed to load
                {
                    Exceptions.ProcessModuleLoadException( this, exc );
                }
            }
        }