private int CreatePortal(out bool createdOk) { string fileName = ddlXMLTemplates.Text; string portalAlias = AliasField.Text; string portalName = TitleField.Text; string portalPath = "/" + PathField.Text; IPortalTemplateRepository repository = new PortalTemplateRepository(); IPortalTemplateServices services = PortalTemplateFactory.GetPortalTemplateServices(repository); int newPortalID = 1; createdOk = services.DeserializePortal(fileName, portalName, portalAlias, portalPath, PortalSettings.PortalFullPath, out newPortalID); if (createdOk && !Config.UseSingleUserBase) { string AdminEmail = "*****@*****.**"; // Create the stradmin User for the new portal UsersDB User = new UsersDB(); // Create the "Admins" role for the new portal Guid roleID = User.AddRole(portalAlias, "Admins"); Guid userID = User.AddUser("admin", AdminEmail, "admin", portalAlias); // Create a new row in a many to many table (userroles) // giving the "admins" role to the stradmin user User.AddUserRole(roleID, userID, portalAlias); PortalsDB portals = new PortalsDB(); portals.CreatePortalPath(portalPath); } return newPortalID; }
/// <summary> /// Save user data /// </summary> /// <returns> /// The user id /// </returns> public Guid SaveUserData() { var returnId = Guid.Empty; if (this.PasswordField.Text.Length > 0 || this.ConfirmPasswordField.Text.Length > 0) { if (this.PasswordField.Text != this.ConfirmPasswordField.Text) { this.ComparePasswords.IsValid = false; } } // Only attempt a login if all form fields on the page are valid if (this.Page.IsValid) { var accountSystem = new UsersDB(); var countryId = string.Empty; if (this.CountryField.SelectedItem != null) { countryId = this.CountryField.SelectedItem.Value; } var stateId = 0; if (this.StateField.SelectedItem != null) { stateId = Convert.ToInt32(this.StateField.SelectedItem.Value); } try { if (this.UserName == string.Empty) { // Add New User to Portal User Database returnId = accountSystem.AddUser( this.NameField.Text, this.CompanyField.Text, this.AddressField.Text, this.CityField.Text, this.ZipField.Text, countryId, stateId, this.PhoneField.Text, this.FaxField.Text, this.PasswordField.Text, this.EmailField.Text, this.SendNewsletter.Checked, CurrentPortalSettings.PortalAlias); } else { // Update user if (this.PasswordField.Text.Equals(this.ConfirmPasswordField.Text) && this.PasswordField.Text.Equals(string.Empty)) { accountSystem.UpdateUser( this.OriginalUserId, this.NameField.Text, this.CompanyField.Text, this.AddressField.Text, this.CityField.Text, this.ZipField.Text, countryId, stateId, this.PhoneField.Text, this.FaxField.Text, this.EmailField.Text, this.SendNewsletter.Checked); } else { accountSystem.UpdateUser( this.OriginalUserId, this.NameField.Text, this.CompanyField.Text, this.AddressField.Text, this.CityField.Text, this.ZipField.Text, countryId, stateId, this.PhoneField.Text, this.FaxField.Text, this.PasswordField.Text, this.EmailField.Text, this.SendNewsletter.Checked, this.PortalSettings.PortalAlias); } // If we are here no error occurred } } catch (Exception ex) { this.Message.Text = General.GetString("REGISTRATION_FAILED", "Registration failed", this.Message) + " - "; if (ex is SqlException) { if (((SqlException)ex).Number == 2627) { this.Message.Text = General.GetString( "REGISTRATION_FAILED_EXISTING_EMAIL_ADDRESS", "Registration has failed. This email address has already been registered. Please use a different email address or use the 'Send Password' button on the login page.", this.Message); } } ErrorHandler.Publish(LogLevel.Error, "Error registering user", ex); } } return returnId; }
public int CreatePortal(int solutionId, string portalAlias, string portalName, string portalPath) { var tabs = new PagesDB(); var modules = new ModulesDB(); // Create a new portal var portalId = this.AddPortal(portalAlias, portalName, portalPath); // get module definitions foreach (var solutionModuleDefinition in modules.GetSolutionModuleDefinitions(solutionId)) { modules.UpdateModuleDefinitions(solutionModuleDefinition.GeneralModuleDefinitionId, portalId, true); } if (!Config.UseSingleUserBase) { const string AdminEmail = "*****@*****.**"; // Create the stradmin User for the new portal var user = new UsersDB(); // Create the "Admins" role for the new portal var roleId = user.AddRole(portalAlias, "Admins"); var userId = user.AddUser(StringsAdmin, AdminEmail, StringsAdmin, portalAlias); // Create the "Admins" profile for the new portal var profile = ProfileBase.Create(AdminEmail); profile.SetPropertyValue("Email", AdminEmail); profile.SetPropertyValue("Name", "admin"); try { profile.Save(); } catch (Exception exc) { } // Create a new row in a many to many table (userroles) // giving the "admins" role to the stradmin user user.AddUserRole(roleId, userId, portalAlias); } // Create a new Page "home" var homePageId = tabs.AddPage(portalId, "Home", 1); // Create a new Page "admin" var localizedString = General.GetString("ADMIN_TAB_NAME"); var adminPageId = tabs.AddPage(portalId, localizedString, StrAdmins, 9999); // Add Modules for portal use // Html Document modules.UpdateModuleDefinitions(new Guid(StrGuidhtmlDocument), portalId, true); // Add Modules for portal administration // Site Settings (Admin) localizedString = General.GetString("MODULE_SITE_SETTINGS"); modules.UpdateModuleDefinitions(new Guid(StrGuidSiteSettings), portalId, true); modules.AddModule( adminPageId, 1, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSiteSettings)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Pages (Admin) localizedString = General.GetString("MODULE_TABS"); modules.UpdateModuleDefinitions(new Guid(StrGuidPages), portalId, true); modules.AddModule( adminPageId, 2, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidPages)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Roles (Admin) localizedString = General.GetString("MODULE_SECURITY_ROLES"); modules.UpdateModuleDefinitions(new Guid(StrGuidSecurityRoles), portalId, true); modules.AddModule( adminPageId, 3, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidSecurityRoles)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Manage Users (Admin) localizedString = General.GetString("MODULE_MANAGE_USERS"); modules.UpdateModuleDefinitions(new Guid(StrGuidManageUsers), portalId, true); modules.AddModule( adminPageId, 4, StrContentPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidManageUsers)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Module Definitions (Admin) localizedString = General.GetString("MODULE_MODULES"); modules.UpdateModuleDefinitions(new Guid(StrGuidModules), portalId, true); modules.AddModule( adminPageId, 1, StringsRightPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidModules)), 0, StrAdmins, StrAllUsers, StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // End Change [email protected] // Change by [email protected] // Add Signin Module and put it on the hometab // Signin localizedString = General.GetString("MODULE_LOGIN", "Login"); modules.UpdateModuleDefinitions(new Guid(StrGuidLogin), portalId, true); modules.AddModule( homePageId, -1, StrLeftPane, localizedString, modules.GetModuleDefinitionByGuid(portalId, new Guid(StrGuidLogin)), 0, StrAdmins, "Unauthenticated Users;Admins;", StrAdmins, StrAdmins, StrAdmins, StrAdmins, StrAdmins, false, string.Empty, false, false, false); // Add language switcher to available modules // Language Switcher modules.UpdateModuleDefinitions(new Guid(StrGuidLanguageSwitcher), portalId, true); // End of change by [email protected] // Create paths this.CreatePortalPath(portalPath); return portalId; }