/// <summary> /// Save Current board / Create new Board /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e) { if (this.BoardId == null && this.CreateAdminUser.Checked) { if (this.UserPass1.Text != this.UserPass2.Text) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITBOARD", "MSG_PASS_MATCH"), MessageTypes.warning); return; } } if (this.BoardId != null) { var cult = StaticDataHelper.Cultures(); var langFile = "en-US"; cult .Where(dataRow => dataRow.CultureTag == this.Culture.SelectedValue) .ForEach(row => langFile = row.CultureFile); // Save current board settings this.GetRepository <Board>().Save( this.BoardId ?? 0, this.Name.Text.Trim(), langFile, this.Culture.SelectedItem.Value); } else { // Create board if (this.CreateAdminUser.Checked) { this.CreateBoard( this.UserName.Text.Trim(), this.UserPass1.Text, this.UserEmail.Text.Trim(), this.Name.Text.Trim(), true); } else { // create admin user from logged in user... this.CreateBoard( null, null, null, this.Name.Text.Trim(), false); } } // Done this.PageContext.BoardSettings = null; BuildLink.Redirect(ForumPages.Admin_Boards); }
/// <summary> /// The save_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Save_Click([NotNull] object sender, [NotNull] EventArgs e) { string languageFile = "english.xml"; var cultures = StaticDataHelper.Cultures().AsEnumerable().Where( c => c.Field <string>("CultureTag").Equals(this.Culture.SelectedValue)); if (cultures.Any()) { languageFile = cultures.First().Field <string>("CultureFile"); } DB.board_save( this.PageContext.PageBoardID, languageFile, this.Culture.SelectedValue, this.Name.Text, this.AllowThreaded.Checked); // save poll group this.PageContext.BoardSettings.BoardPollID = this.PollGroupListDropDown.SelectedIndex.ToType <int>() > 0 ? this.PollGroupListDropDown.SelectedValue.ToType <int>() : 0; this.PageContext.BoardSettings.Language = languageFile; this.PageContext.BoardSettings.Culture = this.Culture.SelectedValue; this.PageContext.BoardSettings.Theme = this.Theme.SelectedValue; // allow null/empty as a mobile theme many not be desired. this.PageContext.BoardSettings.MobileTheme = this.MobileTheme.SelectedValue ?? String.Empty; this.PageContext.BoardSettings.ShowTopicsDefault = this.ShowTopic.SelectedValue.ToType <int>(); this.PageContext.BoardSettings.AllowThemedLogo = this.AllowThemedLogo.Checked; this.PageContext.BoardSettings.FileExtensionAreAllowed = this.FileExtensionAllow.SelectedValue.ToType <int>() == 0 ? true : false; this.PageContext.BoardSettings.NotificationOnUserRegisterEmailList = this.NotificationOnUserRegisterEmailList.Text.Trim(); this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost = this.EmailModeratorsOnModeratedPost.Checked; this.PageContext.BoardSettings.AllowDigestEmail = this.AllowDigestEmail.Checked; this.PageContext.BoardSettings.DefaultSendDigestEmail = this.DefaultSendDigestEmail.Checked; this.PageContext.BoardSettings.DefaultNotificationSetting = this.DefaultNotificationSetting.SelectedValue.ToEnum <UserNotificationSetting>(); // save the settings to the database ((YafLoadBoardSettings)this.PageContext.BoardSettings).SaveRegistry(); // Reload forum settings this.PageContext.BoardSettings = null; // Clearing cache with old users permissions data to get new default styles... this.PageContext.Cache.Remove((x) => x.StartsWith(YafCache.GetBoardCacheKey(Constants.Cache.ActiveUserLazyData))); YafBuildLink.Redirect(ForumPages.admin_admin); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.IsPostBack) { return; } this.Culture.DataSource = StaticDataHelper.Cultures() .AsEnumerable() .OrderBy(x => x.Field <string>("CultureNativeName")) .CopyToDataTable(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; this.BindData(); if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue(this.Get <YafBoardSettings>().Culture).Selected = true; } if (this.BoardId != null) { this.CreateNewAdminHolder.Visible = false; using (var dt = this.GetRepository <Board>().List(this.BoardId)) { var row = dt.Rows[0]; this.Name.Text = (string)row["Name"]; this.AllowThreaded.Checked = Convert.ToBoolean(row["AllowThreaded"]); var membershipAppName = row["MembershipAppName"].ToString(); if (membershipAppName.IsSet()) { this.BoardMembershipAppName.Text = row["MembershipAppName"].ToString(); this.BoardMembershipAppName.Enabled = false; } else { this.BoardMembershipAppNameHolder.Visible = false; } } } else { this.UserName.Text = this.User.UserName; this.UserEmail.Text = this.User.Email; } if (Config.IsDotNetNuke) { this.CreateNewAdminHolder.Visible = false; } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.IsPostBack) { return; } this.Culture.DataSource = StaticDataHelper.Cultures() .AsEnumerable() .OrderBy(x => x.Field <string>("CultureNativeName")) .CopyToDataTable(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; this.BindData(); if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue(this.Get <YafBoardSettings>().Culture).Selected = true; } if (this.BoardId != null) { this.CreateNewAdminHolder.Visible = false; var board = this.GetRepository <Board>().GetById(this.BoardId.Value); this.Name.Text = board.Name; this.AllowThreaded.Checked = board.AllowThreaded; var membershipAppName = board.MembershipAppName; if (membershipAppName.IsSet()) { this.BoardMembershipAppName.Text = membershipAppName; this.BoardMembershipAppName.Enabled = false; } else { this.BoardMembershipAppNameHolder.Visible = false; } } else { this.UserName.Text = this.User.UserName; this.UserEmail.Text = this.User.Email; } if (Config.IsDotNetNuke) { this.CreateNewAdminHolder.Visible = false; } }
/// <summary> /// Binds the data. /// </summary> private void BindData() { var cultureTable = StaticDataHelper.Cultures(); this.List.DataSource = cultureTable; YafContext.Current.PageElements.RegisterJsBlock( "tablesorterLoadJs", JavaScriptBlocks.LoadTableSorter( "#language-table", cultureTable.HasRows() ? "headers: { 4: { sorter: false }}" : null)); this.DataBind(); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { this.PageContext.PageElements.RegisterJsBlockStartup( nameof(JavaScriptBlocks.FormValidatorJs), JavaScriptBlocks.FormValidatorJs(this.Save.ClientID)); if (this.IsPostBack) { return; } this.Culture.DataSource = StaticDataHelper.Cultures().OrderBy(x => x.CultureNativeName); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; this.BindData(); if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue(this.PageContext.BoardSettings.Culture).Selected = true; } if (this.BoardId != null) { this.CreateNewAdminHolder.Visible = false; var board = this.GetRepository <Board>().GetById(this.BoardId.Value); this.Name.Text = board.Name; } else { this.UserName.Text = this.User.UserName; this.UserEmail.Text = this.User.Email; } if (Config.IsDotNetNuke) { this.CreateNewAdminHolder.Visible = false; } }
/// <summary> /// Gets the YAF cultures. /// </summary> /// <returns> /// Dictionary with YAF Cultures /// </returns> public static List <YafCultureInfo> GetYafCultures() { var cult = StaticDataHelper.Cultures(); var yafCultures = (from DataRow row in cult.Rows select new YafCultureInfo { Culture = row["CultureTag"].ToString(), LanguageFile = row["CultureFile"].ToString() }) .ToList(); if (yafCultures.Count == 0) { yafCultures.Add(new YafCultureInfo { Culture = "en", LanguageFile = "english.xml" }); } return(yafCultures); }
/// <summary> /// Initializes the forum. /// </summary> /// <param name="applicationId"> /// The application Id. /// </param> /// <param name="forumName"> /// The forum name. /// </param> /// <param name="culture"> /// The culture. /// </param> /// <param name="forumEmail"> /// The forum email. /// </param> /// <param name="forumLogo"> /// The forum Logo. /// </param> /// <param name="forumBaseUrlMask"> /// The forum base URL mask. /// </param> /// <param name="adminUserName"> /// The admin user name. /// </param> /// <param name="adminEmail"> /// The admin email. /// </param> /// <param name="adminProviderUserKey"> /// The admin provider user key. /// </param> public void InitializeForum( [NotNull] Guid applicationId, [NotNull] string forumName, [NotNull] string culture, [NotNull] string forumEmail, [NotNull] string forumLogo, [NotNull] string forumBaseUrlMask, [NotNull] string adminUserName, [NotNull] string adminEmail, [NotNull] string adminProviderUserKey) { var cult = StaticDataHelper.Cultures(); var langFile = "english.xml"; cult.Where(c => c.CultureTag == culture) .ForEach(c => langFile = c.CultureFile); // -- initialize required 'registry' settings this.GetRepository <Registry>().Save("applicationid", applicationId.ToString()); this.GetRepository <Registry>().Save("version", BoardInfo.AppVersion.ToString()); this.GetRepository <Registry>().Save("versionname", BoardInfo.AppVersionName); this.GetRepository <Registry>().Save("forumemail", forumEmail); this.GetRepository <Registry>().Save("forumlogo", forumLogo); this.GetRepository <Registry>().Save("baseurlmask", forumBaseUrlMask); this.GetRepository <Board>().Create( forumName, forumEmail, culture, langFile, adminUserName, adminEmail, adminProviderUserKey, true, Config.CreateDistinctRoles && Config.IsAnyPortal ? "YAF " : string.Empty); this.AddOrUpdateExtensions(); }
/// <summary> /// The page_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.PageLinks.AddLink(PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum)); this.PageLinks.AddLink("Administration", YafBuildLink.GetLink(ForumPages.admin_admin)); this.PageLinks.AddLink("Boards", string.Empty); this.Culture.DataSource = StaticDataHelper.Cultures(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; BindData(); if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue(this.PageContext.BoardSettings.Culture).Selected = true; } if (BoardID != null) { this.CreateNewAdminHolder.Visible = false; using (DataTable dt = DB.board_list(BoardID)) { DataRow row = dt.Rows[0]; this.Name.Text = (string)row["Name"]; this.AllowThreaded.Checked = SqlDataLayerConverter.VerifyBool(row["AllowThreaded"]); this.BoardMembershipAppName.Text = row["MembershipAppName"].ToString(); } } else { this.UserName.Text = User.UserName; this.UserEmail.Text = User.Email; } } }
/// <summary> /// Initializes the forum. /// </summary> /// <param name="applicationId"> /// The application Id. /// </param> /// <param name="forumName"> /// The forum name. /// </param> /// <param name="timeZone"> /// The time zone. /// </param> /// <param name="culture"> /// The culture. /// </param> /// <param name="forumEmail"> /// The forum email. /// </param> /// <param name="forumLogo"> /// The forum Logo. /// </param> /// <param name="forumBaseUrlMask"> /// The forum base URL mask. /// </param> /// <param name="adminUserName"> /// The admin user name. /// </param> /// <param name="adminEmail"> /// The admin email. /// </param> /// <param name="adminProviderUserKey"> /// The admin provider user key. /// </param> public void InitializeForum( Guid applicationId, string forumName, string timeZone, string culture, string forumEmail, string forumLogo, string forumBaseUrlMask, string adminUserName, string adminEmail, object adminProviderUserKey) { var cult = StaticDataHelper.Cultures(); var langFile = "english.xml"; cult.Where(dataRow => dataRow.CultureTag == culture) .ForEach(dataRow => langFile = dataRow.CultureFile); this.GetRepository <Board>().SystemInitialize( forumName, timeZone, culture, langFile, forumEmail, forumLogo, forumBaseUrlMask, string.Empty, adminUserName, adminEmail, adminProviderUserKey, Config.CreateDistinctRoles && Config.IsAnyPortal ? "YAF " : string.Empty); this.GetRepository <Registry>().Save("applicationid", applicationId.ToString()); this.GetRepository <Registry>().Save("version", BoardInfo.AppVersion.ToString()); this.GetRepository <Registry>().Save("versionname", BoardInfo.AppVersionName); this.ImportStatics(); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.IsPostBack) { return; } this.Culture.DataSource = StaticDataHelper.Cultures().OrderBy(x => x.CultureNativeName); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; this.BindData(); if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue(this.Get <BoardSettings>().Culture).Selected = true; } if (this.BoardId != null) { this.CreateNewAdminHolder.Visible = false; var board = this.GetRepository <Board>().GetById(this.BoardId.Value); this.Name.Text = board.Name; } else { this.UserName.Text = this.User.UserName; this.UserEmail.Text = this.User.Email; } if (Config.IsDotNetNuke) { this.CreateNewAdminHolder.Visible = false; } }
/// <summary> /// Save Current board / Create new Board /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Save_Click([NotNull] object sender, [NotNull] EventArgs e) { if (this.Name.Text.Trim().Length == 0) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITBOARD", "MSG_NAME_BOARD"), MessageTypes.Warning); return; } if (this.BoardID == null && this.CreateAdminUser.Checked) { if (this.UserName.Text.Trim().Length == 0) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITBOARD", "MSG_NAME_ADMIN"), MessageTypes.Warning); return; } if (this.UserEmail.Text.Trim().Length == 0) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITBOARD", "MSG_EMAIL_ADMIN"), MessageTypes.Warning); return; } if (this.UserPass1.Text.Trim().Length == 0) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITBOARD", "MSG_PASS_ADMIN"), MessageTypes.Warning); return; } if (this.UserPass1.Text != this.UserPass2.Text) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITBOARD", "MSG_PASS_MATCH"), MessageTypes.Warning); return; } } if (this.BoardID != null) { DataTable cult = StaticDataHelper.Cultures(); string langFile = "en-US"; foreach (DataRow drow in cult.Rows.Cast <DataRow>().Where(drow => drow["CultureTag"].ToString() == this.Culture.SelectedValue) ) { langFile = (string)drow["CultureFile"]; } // Save current board settings this.GetRepository <Board>() .Save( this.BoardID ?? 0, this.Name.Text.Trim(), langFile, this.Culture.SelectedItem.Value, this.AllowThreaded.Checked); } else { // Create board // MEK says : Purposefully set MembershipAppName without including RolesAppName yet, as the current providers don't support different Appnames. if (this.CreateAdminUser.Checked) { this.CreateBoard( this.UserName.Text.Trim(), this.UserPass1.Text, this.UserEmail.Text.Trim(), this.UserPasswordQuestion.Text.Trim(), this.UserPasswordAnswer.Text.Trim(), this.Name.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), true); } else { // create admin user from logged in user... this.CreateBoard( null, null, null, null, null, this.Name.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), false); } } // Done this.PageContext.BoardSettings = null; YafBuildLink.Redirect(ForumPages.admin_boards); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.IsPostBack) { return; } this.PageLinks.AddLink(this.Get <YafBoardSettings>().Name, YafBuildLink.GetLink(ForumPages.forum)); this.PageLinks.AddLink( this.GetText("ADMIN_ADMIN", "Administration"), YafBuildLink.GetLink(ForumPages.admin_admin)); this.PageLinks.AddLink( this.GetText("ADMIN_BOARDS", "TITLE"), YafBuildLink.GetLink(ForumPages.admin_editboard)); this.PageLinks.AddLink(this.GetText("ADMIN_EDITBOARD", "TITLE"), string.Empty); this.Page.Header.Title = "{0} - {1} - {2}".FormatWith( this.GetText("ADMIN_ADMIN", "Administration"), this.GetText("ADMIN_BOARDS", "TITLE"), this.GetText("ADMIN_EDITBOARD", "TITLE")); this.Save.Text = this.GetText("SAVE"); this.Cancel.Text = this.GetText("CANCEL"); this.Culture.DataSource = StaticDataHelper.Cultures() .AsEnumerable() .OrderBy(x => x.Field <string>("CultureNativeName")) .CopyToDataTable(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; this.BindData(); if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue(this.Get <YafBoardSettings>().Culture).Selected = true; } if (this.BoardID != null) { this.CreateNewAdminHolder.Visible = false; using (DataTable dt = this.GetRepository <Board>().List(this.BoardID)) { DataRow row = dt.Rows[0]; this.Name.Text = (string)row["Name"]; this.AllowThreaded.Checked = Convert.ToBoolean(row["AllowThreaded"]); var membershipAppName = row["MembershipAppName"].ToString(); if (membershipAppName.IsSet()) { this.BoardMembershipAppName.Text = row["MembershipAppName"].ToString(); this.BoardMembershipAppName.Enabled = false; } else { this.BoardMembershipAppNameHolder.Visible = false; } } } else { this.UserName.Text = this.User.UserName; this.UserEmail.Text = this.User.Email; } }
/// <summary> /// The create board. /// </summary> /// <param name="adminName">The admin name.</param> /// <param name="adminPassword">The admin password.</param> /// <param name="adminEmail">The admin email.</param> /// <param name="adminPasswordQuestion">The admin password question.</param> /// <param name="adminPasswordAnswer">The admin password answer.</param> /// <param name="boardName">The board name.</param> /// <param name="boardMembershipAppName">The board membership app name.</param> /// <param name="boardRolesAppName">The board roles app name.</param> /// <param name="createUserAndRoles">The create user and roles.</param> protected bool CreateBoard( [NotNull] string adminName, [NotNull] string adminPassword, [NotNull] string adminEmail, [NotNull] string adminPasswordQuestion, [NotNull] string adminPasswordAnswer, [NotNull] string boardName, [NotNull] string boardMembershipAppName, [NotNull] string boardRolesAppName, bool createUserAndRoles) { // Store current App Names string currentMembershipAppName = this.Get <MembershipProvider>().ApplicationName; string currentRolesAppName = this.Get <RoleProvider>().ApplicationName; if (boardMembershipAppName.IsSet() && boardRolesAppName.IsSet()) { // Change App Names for new board this.Get <MembershipProvider>().ApplicationName = boardMembershipAppName; this.Get <MembershipProvider>().ApplicationName = boardRolesAppName; } int newBoardID; DataTable cult = StaticDataHelper.Cultures(); string langFile = "english.xml"; foreach (DataRow drow in cult.Rows.Cast <DataRow>().Where(drow => drow["CultureTag"].ToString() == this.Culture.SelectedValue)) { langFile = (string)drow["CultureFile"]; } if (createUserAndRoles) { // Create new admin users MembershipCreateStatus createStatus; MembershipUser newAdmin = this.Get <MembershipProvider>() .CreateUser( adminName, adminPassword, adminEmail, adminPasswordQuestion, adminPasswordAnswer, true, null, out createStatus); if (createStatus != MembershipCreateStatus.Success) { this.PageContext.AddLoadMessage( "Create User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(createStatus)), MessageTypes.Error); return(false); } // Create groups required for the new board RoleMembershipHelper.CreateRole("Administrators"); RoleMembershipHelper.CreateRole("Registered"); // Add new admin users to group RoleMembershipHelper.AddUserToRole(newAdmin.UserName, "Administrators"); // Create Board newBoardID = this.DbCreateBoard( boardName, boardMembershipAppName, boardRolesAppName, langFile, newAdmin); } else { // new admin MembershipUser newAdmin = UserMembershipHelper.GetUser(); // Create Board newBoardID = this.DbCreateBoard( boardName, boardMembershipAppName, boardRolesAppName, langFile, newAdmin); } if (newBoardID > 0 && Config.MultiBoardFolders) { // Successfully created the new board string boardFolder = this.Server.MapPath(Path.Combine(Config.BoardRoot, "{0}/".FormatWith(newBoardID))); // Create New Folders. if (!Directory.Exists(Path.Combine(boardFolder, "Images"))) { // Create the Images Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images")); // Create Sub Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Emoticons")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Ranks")); } if (!Directory.Exists(Path.Combine(boardFolder, "Themes"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Themes")); // Need to copy default theme to the Themes Folder } if (!Directory.Exists(Path.Combine(boardFolder, "Uploads"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads")); } } // Return application name to as they were before. this.Get <MembershipProvider>().ApplicationName = currentMembershipAppName; this.Get <RoleProvider>().ApplicationName = currentRolesAppName; return(true); }
/// <summary> /// The create board. /// </summary> /// <param name="adminName">The admin name.</param> /// <param name="adminPassword">The admin password.</param> /// <param name="adminEmail">The admin email.</param> /// <param name="boardName">The board name.</param> /// <param name="createUserAndRoles">The create user and roles.</param> /// <returns>Returns if the board was created or not</returns> protected bool CreateBoard( [NotNull] string adminName, [NotNull] string adminPassword, [NotNull] string adminEmail, [NotNull] string boardName, bool createUserAndRoles) { int newBoardId; var cult = StaticDataHelper.Cultures(); var langFile = "english.xml"; cult.Where(dataRow => dataRow.CultureTag == this.Culture.SelectedValue) .ForEach(row => langFile = row.CultureFile); if (createUserAndRoles) { var user = new AspNetUsers { Id = Guid.NewGuid().ToString(), ApplicationId = this.Get <BoardSettings>().ApplicationId, UserName = adminName, LoweredUserName = adminName, Email = adminEmail, IsApproved = true }; // Create new admin users var result = this.Get <IAspNetUsersHelper>().Create(user, adminPassword); if (!result.Succeeded) { this.PageContext.AddLoadMessage( $"Create User Failed: {result.Errors.FirstOrDefault()}", MessageTypes.danger); return(false); } // Create groups required for the new board AspNetRolesHelper.CreateRole("Administrators"); AspNetRolesHelper.CreateRole("Registered"); // Add new admin users to group AspNetRolesHelper.AddUserToRole(user, "Administrators"); // Create Board newBoardId = this.DbCreateBoard( boardName, langFile, user); } else { // new admin var newAdmin = this.Get <IAspNetUsersHelper>().GetUser(); // Create Board newBoardId = this.DbCreateBoard( boardName, langFile, newAdmin); } if (newBoardId <= 0 || !Config.MultiBoardFolders) { return(true); } // Successfully created the new board var boardFolder = this.Server.MapPath(Path.Combine(Config.BoardRoot, $"{newBoardId}/")); // Create New Folders. if (!Directory.Exists(Path.Combine(boardFolder, "Images"))) { // Create the Images Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images")); // Create Sub Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals")); } if (!Directory.Exists(Path.Combine(boardFolder, "Uploads"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads")); } return(true); }
/// <summary> /// The bind data. /// </summary> private void BindData() { List.DataSource = StaticDataHelper.Cultures(); DataBind(); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.IsPostBack) { return; } var boardSettings = this.Get <BoardSettings>(); this.CdvVersion.Text = boardSettings.CdvVersion.ToString(); // create list boxes by populating data sources from Data class var themeData = StaticDataHelper.Themes(); if (themeData.Any()) { this.Theme.DataSource = themeData; } this.Culture.DataSource = StaticDataHelper.Cultures().AsEnumerable() .OrderBy(x => x.Field <string>("CultureNativeName")).CopyToDataTable(); this.Culture.DataTextField = "CultureNativeName"; this.Culture.DataValueField = "CultureTag"; this.ShowTopic.DataSource = StaticDataHelper.TopicTimes(); this.ShowTopic.DataTextField = "TopicText"; this.ShowTopic.DataValueField = "TopicValue"; this.BindData(); // bind poll group list var pollGroup = this.GetRepository <Poll>() .PollGroupList(this.PageContext.PageUserID, null, this.PageContext.PageBoardID).Distinct( new AreEqualFunc <TypedPollGroup>((v1, v2) => v1.PollGroupID == v2.PollGroupID)).ToList(); pollGroup.Insert(0, new TypedPollGroup(this.GetText("NONE"), -1)); // TODO: vzrus needs some work, will be in polls only until feature is debugged there. this.PollGroupListDropDown.Items.AddRange( pollGroup.Select(x => new ListItem(x.Question, x.PollGroupID.ToString())).ToArray()); // population default notification setting options... var items = EnumHelper.EnumToDictionary <UserNotificationSetting>(); if (!boardSettings.AllowNotificationAllPostsAllTopics) { // remove it... items.Remove(UserNotificationSetting.AllTopics.ToInt()); } var notificationItems = items.Select( x => new ListItem( HtmlHelper.StripHtml(this.GetText("SUBSCRIPTIONS", x.Value)), x.Key.ToString())) .ToArray(); this.DefaultNotificationSetting.Items.AddRange(notificationItems); // Get first default full culture from a language file tag. var langFileCulture = StaticDataHelper.CultureDefaultFromFile(boardSettings.Language) ?? "en-US"; if (boardSettings.Theme.Contains(".xml")) { SetSelectedOnList(ref this.Theme, "yaf"); } else { SetSelectedOnList(ref this.Theme, boardSettings.Theme); } // If 2-letter language code is the same we return Culture, else we return a default full culture from language file /* SetSelectedOnList( * ref this.Culture, * langFileCulture.Substring(0, 2) == this.Get<BoardSettings>().Culture * ? this.Get<BoardSettings>().Culture * : langFileCulture);*/ SetSelectedOnList(ref this.Culture, boardSettings.Culture); if (this.Culture.SelectedIndex == 0) { // If 2-letter language code is the same we return Culture, else we return a default full culture from language file SetSelectedOnList( ref this.Culture, langFileCulture.Substring(0, 2) == boardSettings.Culture ? boardSettings.Culture : langFileCulture); } SetSelectedOnList(ref this.ShowTopic, boardSettings.ShowTopicsDefault.ToString()); SetSelectedOnList( ref this.DefaultNotificationSetting, boardSettings.DefaultNotificationSetting.ToInt().ToString()); this.FileExtensionAllow.Checked = boardSettings.FileExtensionAreAllowed; this.NotificationOnUserRegisterEmailList.Text = boardSettings.NotificationOnUserRegisterEmailList; this.EmailModeratorsOnModeratedPost.Checked = boardSettings.EmailModeratorsOnModeratedPost; this.EmailModeratorsOnReportedPost.Checked = boardSettings.EmailModeratorsOnReportedPost; this.AllowDigestEmail.Checked = boardSettings.AllowDigestEmail; this.DefaultSendDigestEmail.Checked = boardSettings.DefaultSendDigestEmail; this.ForumEmail.Text = boardSettings.ForumEmail; this.ForumBaseUrlMask.Text = boardSettings.BaseUrlMask; var item = this.BoardLogo.Items.FindByText(boardSettings.ForumLogo); if (item != null) { item.Selected = true; } this.CopyrightRemovalKey.Text = boardSettings.CopyrightRemovalDomainKey; this.DigestSendEveryXHours.Text = boardSettings.DigestSendEveryXHours.ToString(); if (boardSettings.BoardPollID > 0) { this.PollGroupListDropDown.SelectedValue = boardSettings.BoardPollID.ToString(); } else { this.PollGroupListDropDown.SelectedIndex = 0; } this.PollGroupList.Visible = true; // Copyright Link-back Algorithm // Please keep if you haven't purchased a removal or commercial license. this.CopyrightHolder.Visible = true; // Render board Announcement // add items to the dropdown this.BoardAnnouncementUntilUnit.Items.Add(new ListItem(this.GetText("PROFILE", "MONTH"), "3")); this.BoardAnnouncementUntilUnit.Items.Add(new ListItem(this.GetText("PROFILE", "DAYS"), "1")); this.BoardAnnouncementUntilUnit.Items.Add(new ListItem(this.GetText("PROFILE", "HOURS"), "2")); // select hours this.BoardAnnouncementUntilUnit.SelectedIndex = 0; // default number of hours to suspend user for this.BoardAnnouncementUntil.Text = "1"; if (boardSettings.BoardAnnouncement.IsNotSet()) { return; } this.CurrentAnnouncement.Visible = true; this.CurrentMessage.Text = $"{this.GetText("ANNOUNCEMENT_CURRENT")}: {boardSettings.BoardAnnouncementUntil}"; this.BoardAnnouncementType.SelectedValue = boardSettings.BoardAnnouncementType; this.BoardAnnouncement.Text = boardSettings.BoardAnnouncement; }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { var errorMessage = this.InstallWizard.FindControlAs <PlaceHolder>("ErrorMessage"); if (this._loadMessage.IsNotSet()) { errorMessage.Visible = false; } if (this.IsPostBack) { return; } if (this.Session["InstallWizardFinal"] != null) { this.CurrentWizardStepID = "WizFinished"; this.Session.Remove("InstallWizardFinal"); } else { this.Cache["DBVersion"] = LegacyDb.GetDBVersion(); this.CurrentWizardStepID = this.IsConfigPasswordSet && this.IsForumInstalled ? "WizEnterPassword" : "WizWelcome"; // "WizCreatePassword" if (!this.IsConfigPasswordSet) { // fake the board settings YafContext.Current.BoardSettings = new YafBoardSettings(); } this.FullTextSupport.Visible = this.DbAccess.Information.FullTextScript.IsSet() && this.Get <IDbFunction>().IsFullTextSupported(); this.TimeZones.DataSource = StaticDataHelper.TimeZones(); this.Culture.DataSource = StaticDataHelper.Cultures(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; this.DataBind(); this.TimeZones.Items.FindByValue(TimeZoneInfo.Local.Id).Selected = true; if (this.Culture.Items.Count > 0) { this.Culture.Items.FindByValue("en-US").Selected = true; } this.ForumBaseUrlMask.Text = BaseUrlBuilder.GetBaseUrlFromVariables(); this.DBUsernamePasswordHolder.Visible = LegacyDb.PasswordPlaceholderVisible; // Connection string parameters text boxes foreach (var paramNumber in Enumerable.Range(1, 20)) { var dbParam = this.DbAccess.Information.DbConnectionParameters.FirstOrDefault(p => p.ID == paramNumber); var label = this.FindControlRecursiveAs <Label>("Parameter{0}_Name".FormatWith(paramNumber)); if (label != null) { label.Text = dbParam != null ? dbParam.Name : string.Empty; } var control = this.FindControlRecursive("Parameter{0}_Value".FormatWith(paramNumber)); if (control is TextBox) { var textBox = control as TextBox; if (dbParam != null) { textBox.Text = dbParam.Value; textBox.Visible = true; } else { textBox.Text = string.Empty; textBox.Visible = false; } } else if (control is CheckBox) { var checkBox = control as CheckBox; if (dbParam != null) { checkBox.Checked = dbParam.Value.ToType <bool>(); checkBox.Visible = true; } else { checkBox.Checked = false; checkBox.Visible = false; } } } // Hide New User on DNN if (!Config.IsDotNetNuke) { return; } this.UserChoice.SelectedIndex = 1; this.UserChoice.Items[0].Enabled = false; this.ExistingUserHolder.Visible = true; this.CreateAdminUserHolder.Visible = false; } }
/// <summary> /// Saves the Updated Profile /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void UpdateProfile_Click([NotNull] object sender, [NotNull] EventArgs e) { var userName = UserMembershipHelper.GetUserNameFromID(this.currentUserId); if (this.HomePage.Text.IsSet()) { // add http:// by default if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*")) { this.HomePage.Text = "http://{0}".FormatWith(this.HomePage.Text.Trim()); } if (!ValidationHelper.IsValidURL(this.HomePage.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.warning); return; } if (this.UserData.NumPosts < this.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount) { string result; // Check for spam if (this.Get <ISpamWordCheck>().CheckForSpamWord(this.HomePage.Text, out result)) { // Log and Send Message to Admins if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user changed the profile Homepage url to: {2}" .FormatWith(userName, this.currentUserId, this.HomePage.Text), EventLogTypes.SpamBotDetected); } else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user changed the profile Homepage url to: {2}, user was deleted and the name, email and IP Address are banned." .FormatWith(userName, this.currentUserId, this.HomePage.Text), EventLogTypes.SpamBotDetected); // Kill user if (!this.PageContext.CurrentForumPage.IsAdminPage) { var user = UserMembershipHelper.GetMembershipUserById(this.currentUserId); var userId = this.currentUserId; var userIp = new CombinedUserDataHelper(user, userId).LastIP; UserMembershipHelper.DeleteAndBanUser(this.currentUserId, user, userIp); } } } } } if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.warning); return; } if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_MSN"), MessageTypes.warning); return; } if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.warning); return; } if (this.ICQ.Text.IsSet() && !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text))) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.warning); return; } if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.warning); return; } if (this.Google.Text.IsSet() && !ValidationHelper.IsValidURL(this.Google.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_GOOGLE"), MessageTypes.warning); return; } string displayName = null; if (this.Get <YafBoardSettings>().EnableDisplayName && this.Get <YafBoardSettings>().AllowDisplayNameModification) { // Check if name matches the required minimum length if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().DisplayNameMinLength), MessageTypes.warning); return; } // Check if name matches the required minimum length if (this.DisplayName.Text.Length > this.Get <YafBoardSettings>().UserNameMaxLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().UserNameMaxLength), MessageTypes.warning); return; } if (this.DisplayName.Text.Trim() != this.UserData.DisplayName) { if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue) { this.PageContext.AddLoadMessage( this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"), MessageTypes.warning); return; } displayName = this.DisplayName.Text.Trim(); } } if (this.UpdateEmailFlag) { var newEmail = this.Email.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.warning); return; } var userNameFromEmail = this.Get <MembershipProvider>().GetUserNameByEmail(this.Email.Text.Trim()); if (userNameFromEmail.IsSet() && userNameFromEmail != userName) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.warning); return; } if (this.Get <YafBoardSettings>().EmailVerification) { this.SendEmailVerification(newEmail); } else { // just update the e-mail... try { UserMembershipHelper.UpdateEmail(this.currentUserId, this.Email.Text.Trim()); } catch (ApplicationException) { this.PageContext.AddLoadMessage( this.GetText("PROFILE", "DUPLICATED_EMAIL"), MessageTypes.warning); return; } } } if (this.Interests.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400), MessageTypes.warning); return; } if (this.Occupation.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400), MessageTypes.warning); return; } this.UpdateUserProfile(userName); // vzrus: We should do it as we need to write null value to db, else it will be empty. // Localizer currently treats only nulls. object language = null; object culture = this.Culture.SelectedValue; object theme = this.Theme.SelectedValue; object editor = this.ForumEditor.SelectedValue; if (this.Theme.SelectedValue.IsNotSet()) { theme = null; } if (this.ForumEditor.SelectedValue.IsNotSet()) { editor = null; } if (this.Culture.SelectedValue.IsNotSet()) { culture = null; } else { foreach (var row in StaticDataHelper.Cultures() .Rows.Cast <DataRow>() .Where(row => culture.ToString() == row["CultureTag"].ToString())) { language = row["CultureFile"].ToString(); } } // save remaining settings to the DB LegacyDb.user_save( this.currentUserId, this.PageContext.PageBoardID, null, displayName, null, this.TimeZones.SelectedValue.ToType <int>(), language, culture, theme, editor, this.UseMobileTheme.Checked, null, null, null, this.DSTUser.Checked, this.HideMe.Checked, null); // vzrus: If it's a guest edited by an admin registry value should be changed var dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.currentUserId, true, null, null, false); if (dt.HasRows() && dt.Rows[0]["IsGuest"].ToType <bool>()) { LegacyDb.registry_save("timezone", this.TimeZones.SelectedValue, this.PageContext.PageBoardID); } // clear the cache for this user...) this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserId)); this.Get <IDataCache>().Clear(); if (!this.PageContext.CurrentForumPage.IsAdminPage) { YafBuildLink.Redirect(ForumPages.cp_profile); } else { this.userData = null; this.BindData(); } }
/// <summary> /// Save the Board Settings /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Save_Click([NotNull] object sender, [NotNull] EventArgs e) { string languageFile = "english.xml"; var cultures = StaticDataHelper.Cultures().AsEnumerable().Where( c => c.Field <string>("CultureTag").Equals(this.Culture.SelectedValue)); if (cultures.Any()) { languageFile = cultures.First().Field <string>("CultureFile"); } this.GetRepository <Board>() .Save( this.PageContext.PageBoardID, this.Name.Text, languageFile, this.Culture.SelectedValue, this.AllowThreaded.Checked); // save poll group var boardSettings = this.Get <YafBoardSettings>(); boardSettings.BoardPollID = this.PollGroupListDropDown.SelectedIndex.ToType <int>() > 0 ? this.PollGroupListDropDown.SelectedValue.ToType <int>() : 0; boardSettings.Language = languageFile; boardSettings.Culture = this.Culture.SelectedValue; boardSettings.Theme = this.Theme.SelectedValue; // allow null/empty as a mobile theme many not be desired. boardSettings.MobileTheme = this.MobileTheme.SelectedValue ?? string.Empty; boardSettings.ShowTopicsDefault = this.ShowTopic.SelectedValue.ToType <int>(); boardSettings.AllowThemedLogo = this.AllowThemedLogo.Checked; boardSettings.FileExtensionAreAllowed = this.FileExtensionAllow.SelectedValue.ToType <int>() == 0; boardSettings.NotificationOnUserRegisterEmailList = this.NotificationOnUserRegisterEmailList.Text.Trim(); boardSettings.EmailModeratorsOnModeratedPost = this.EmailModeratorsOnModeratedPost.Checked; boardSettings.EmailModeratorsOnReportedPost = this.EmailModeratorsOnReportedPost.Checked; boardSettings.AllowDigestEmail = this.AllowDigestEmail.Checked; boardSettings.DefaultSendDigestEmail = this.DefaultSendDigestEmail.Checked; boardSettings.DefaultNotificationSetting = this.DefaultNotificationSetting.SelectedValue.ToEnum <UserNotificationSetting>(); boardSettings.ForumEmail = this.ForumEmail.Text; boardSettings.BaseUrlMask = this.ForumBaseUrlMask.Text; boardSettings.CopyrightRemovalDomainKey = this.CopyrightRemovalKey.Text.Trim(); boardSettings.JqueryUITheme = this.JqueryUITheme.SelectedValue; int hours; if (!int.TryParse(this.DigestSendEveryXHours.Text, out hours)) { hours = 24; } boardSettings.DigestSendEveryXHours = hours; // save the settings to the database ((YafLoadBoardSettings)boardSettings).SaveRegistry(); // Reload forum settings this.PageContext.BoardSettings = null; // Clearing cache with old users permissions data to get new default styles... this.Get <IDataCache>().Remove(x => x.StartsWith(Constants.Cache.ActiveUserLazyData)); YafBuildLink.Redirect(ForumPages.admin_admin); }
/// <summary> /// The update profile_ click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void UpdateProfile_Click([NotNull] object sender, [NotNull] EventArgs e) { if (this.HomePage.Text.IsSet()) { // add http:// by default if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*")) { this.HomePage.Text = "http://{0}".FormatWith(this.HomePage.Text.Trim()); } if (!ValidationHelper.IsValidURL(this.HomePage.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.Warning); return; } } if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.Warning); return; } if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_MSN"), MessageTypes.Warning); return; } if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.Warning); return; } if (this.ICQ.Text.IsSet() && !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text))) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.Warning); return; } if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.Warning); return; } if (this.Google.Text.IsSet() && !ValidationHelper.IsValidURL(this.Google.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_GOOGLE"), MessageTypes.Warning); return; } string displayName = null; if (this.Get <YafBoardSettings>().EnableDisplayName && this.Get <YafBoardSettings>().AllowDisplayNameModification) { // Check if name matches the required minimum length if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().DisplayNameMinLength), MessageTypes.Warning); return; } // Check if name matches the required minimum length if (this.DisplayName.Text.Length > this.Get <YafBoardSettings>().UserNameMaxLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().UserNameMaxLength), MessageTypes.Warning); return; } if (this.DisplayName.Text.Trim() != this.UserData.DisplayName) { if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue) { this.PageContext.AddLoadMessage(this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"), MessageTypes.Warning); return; } displayName = this.DisplayName.Text.Trim(); } } string userName = UserMembershipHelper.GetUserNameFromID(this.currentUserID); if (this.UpdateEmailFlag) { string newEmail = this.Email.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning); return; } string userNameFromEmail = this.Get <MembershipProvider>().GetUserNameByEmail(this.Email.Text.Trim()); if (userNameFromEmail.IsSet() && userNameFromEmail != userName) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning); return; } if (this.Get <YafBoardSettings>().EmailVerification) { this.SendEmailVerification(newEmail); } else { // just update the e-mail... try { UserMembershipHelper.UpdateEmail(this.currentUserID, this.Email.Text.Trim()); } catch (ApplicationException) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "DUPLICATED_EMAIL"), MessageTypes.Warning); return; } } } if (this.Interests.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400), MessageTypes.Warning); return; } if (this.Occupation.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400), MessageTypes.Warning); return; } this.UpdateUserProfile(userName); // vzrus: We should do it as we need to write null value to db, else it will be empty. // Localizer currently treats only nulls. object language = null; object culture = this.Culture.SelectedValue; object theme = this.Theme.SelectedValue; object editor = this.ForumEditor.SelectedValue; if (this.Theme.SelectedValue.IsNotSet()) { theme = null; } if (this.ForumEditor.SelectedValue.IsNotSet()) { editor = null; } if (this.Culture.SelectedValue.IsNotSet()) { culture = null; } else { foreach (DataRow row in StaticDataHelper.Cultures() .Rows.Cast <DataRow>() .Where(row => culture.ToString() == row["CultureTag"].ToString())) { language = row["CultureFile"].ToString(); } } // save remaining settings to the DB LegacyDb.user_save( this.currentUserID, this.PageContext.PageBoardID, null, displayName, null, this.TimeZones.SelectedValue.ToType <int>(), language, culture, theme, editor, this.UseMobileTheme.Checked, null, null, null, this.DSTUser.Checked, this.HideMe.Checked, null); // vzrus: If it's a guest edited by an admin registry value should be changed DataTable dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.currentUserID, true, null, null, false); if (dt.Rows.Count > 0 && dt.Rows[0]["IsGuest"].ToType <bool>()) { LegacyDb.registry_save("timezone", this.TimeZones.SelectedValue, this.PageContext.PageBoardID); } // clear the cache for this user...) this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserID)); YafContext.Current.Get <IDataCache>().Clear(); if (!this.adminEditMode) { YafBuildLink.Redirect(ForumPages.cp_profile); } else { this._userData = null; this.BindData(); } }
/// <summary> /// The page_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (!this.IsPostBack) { this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum)); this.PageLinks.AddLink("Administration", YafBuildLink.GetLink(ForumPages.admin_admin)); this.PageLinks.AddLink("Board Settings", string.Empty); // create list boxes by populating datasources from Data class var themeData = StaticDataHelper.Themes().AsEnumerable().Where(x => !x.Field <bool>("IsMobile")); if (themeData.Any()) { this.Theme.DataSource = themeData.CopyToDataTable(); this.Theme.DataTextField = "Theme"; this.Theme.DataValueField = "FileName"; } var mobileThemeData = StaticDataHelper.Themes().AsEnumerable().Where(x => x.Field <bool>("IsMobile")); if (mobileThemeData.Any()) { this.MobileTheme.DataSource = mobileThemeData.CopyToDataTable(); this.MobileTheme.DataTextField = "Theme"; this.MobileTheme.DataValueField = "FileName"; } this.Culture.DataSource = StaticDataHelper.Cultures().AsEnumerable().OrderBy(x => x.Field <string>("CultureNativeName")).CopyToDataTable( ); this.Culture.DataTextField = "CultureNativeName"; this.Culture.DataValueField = "CultureTag"; this.ShowTopic.DataSource = StaticDataHelper.TopicTimes(); this.ShowTopic.DataTextField = "TopicText"; this.ShowTopic.DataValueField = "TopicValue"; this.FileExtensionAllow.DataSource = StaticDataHelper.AllowDisallow(); this.FileExtensionAllow.DataTextField = "Text"; this.FileExtensionAllow.DataValueField = "Value"; this.BindData(); // bind poll group list var pollGroup = DB.PollGroupList(this.PageContext.PageUserID, null, this.PageContext.PageBoardID).Distinct( new AreEqualFunc <TypedPollGroup>((v1, v2) => v1.PollGroupID == v2.PollGroupID)).ToList(); pollGroup.Insert(0, new TypedPollGroup(String.Empty, -1)); // TODO: vzrus needs some work, will be in polls only until feature is debugged there. this.PollGroupListDropDown.Items.AddRange( pollGroup.Select(x => new ListItem(x.Question, x.PollGroupID.ToString())).ToArray()); // population default notification setting options... var items = EnumHelper.EnumToDictionary <UserNotificationSetting>(); if (!this.PageContext.BoardSettings.AllowNotificationAllPostsAllTopics) { // remove it... items.Remove(UserNotificationSetting.AllTopics.ToInt()); } var notificationItems = items.Select( x => new ListItem( HtmlHelper.StripHtml(this.PageContext.Localization.GetText("CP_SUBSCRIPTIONS", x.Value)), x.Key.ToString())) .ToArray(); this.DefaultNotificationSetting.Items.AddRange(notificationItems); // Get first default full culture from a language file tag. string langFileCulture = StaticDataHelper.CultureDefaultFromFile(this.PageContext.BoardSettings.Language) ?? "en"; SetSelectedOnList(ref this.Theme, this.PageContext.BoardSettings.Theme); SetSelectedOnList(ref this.MobileTheme, this.PageContext.BoardSettings.MobileTheme); // If 2-letter language code is the same we return Culture, else we return a default full culture from language file SetSelectedOnList( ref this.Culture, langFileCulture.Substring(0, 2) == this.PageContext.BoardSettings.Culture ? this.PageContext.BoardSettings.Culture : langFileCulture); SetSelectedOnList(ref this.ShowTopic, this.PageContext.BoardSettings.ShowTopicsDefault.ToString()); SetSelectedOnList( ref this.FileExtensionAllow, this.PageContext.BoardSettings.FileExtensionAreAllowed ? "0" : "1"); SetSelectedOnList( ref this.DefaultNotificationSetting, this.PageContext.BoardSettings.DefaultNotificationSetting.ToInt().ToString()); this.NotificationOnUserRegisterEmailList.Text = this.PageContext.BoardSettings.NotificationOnUserRegisterEmailList; this.AllowThemedLogo.Checked = this.PageContext.BoardSettings.AllowThemedLogo; this.EmailModeratorsOnModeratedPost.Checked = this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost; this.AllowDigestEmail.Checked = this.PageContext.BoardSettings.AllowDigestEmail; this.DefaultSendDigestEmail.Checked = this.PageContext.BoardSettings.DefaultSendDigestEmail; if (this.PageContext.BoardSettings.BoardPollID > 0) { this.PollGroupListDropDown.SelectedValue = this.PageContext.BoardSettings.BoardPollID.ToString(); } else { this.PollGroupListDropDown.SelectedIndex = 0; } this.PollGroupList.Visible = true; } }
/// <summary> /// Save the Board Settings /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e) { var languageFile = "english.xml"; var cultures = StaticDataHelper.Cultures() .Where(c => c.CultureTag.Equals(this.Culture.SelectedValue)).ToList(); if (cultures.Any()) { languageFile = cultures.FirstOrDefault().CultureFile; } this.GetRepository <Board>().Save( this.PageContext.PageBoardID, this.Name.Text, languageFile, this.Culture.SelectedValue); // save poll group var boardSettings = this.Get <BoardSettings>(); boardSettings.Language = languageFile; boardSettings.Culture = this.Culture.SelectedValue; boardSettings.Theme = this.Theme.SelectedValue; // allow null/empty as a mobile theme many not be desired. boardSettings.ShowTopicsDefault = this.ShowTopic.SelectedValue.ToType <int>(); boardSettings.NotificationOnUserRegisterEmailList = this.NotificationOnUserRegisterEmailList.Text.Trim(); boardSettings.EmailModeratorsOnModeratedPost = this.EmailModeratorsOnModeratedPost.Checked; boardSettings.EmailModeratorsOnReportedPost = this.EmailModeratorsOnReportedPost.Checked; boardSettings.AllowDigestEmail = this.AllowDigestEmail.Checked; boardSettings.DefaultSendDigestEmail = this.DefaultSendDigestEmail.Checked; boardSettings.DefaultNotificationSetting = this.DefaultNotificationSetting.SelectedValue.ToEnum <UserNotificationSetting>(); boardSettings.ForumEmail = this.ForumEmail.Text; if (this.BoardLogo.SelectedIndex > 0) { boardSettings.ForumLogo = this.BoardLogo.SelectedItem.Text; } boardSettings.BaseUrlMask = this.ForumBaseUrlMask.Text; boardSettings.CopyrightRemovalDomainKey = this.CopyrightRemovalKey.Text.Trim(); if (!int.TryParse(this.DigestSendEveryXHours.Text, out var hours)) { hours = 24; } boardSettings.DigestSendEveryXHours = hours; // save the settings to the database ((LoadBoardSettings)boardSettings).SaveRegistry(); // Reload forum settings this.PageContext.BoardSettings = null; // Clearing cache with old users permissions data to get new default styles... this.Get <IDataCache>().Remove(x => x.StartsWith(Constants.Cache.ActiveUserLazyData)); BuildLink.Redirect(ForumPages.Admin_Admin); }
/// <summary> /// The save_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Save_Click(object sender, EventArgs e) { if (this.Name.Text.Trim().Length == 0) { this.PageContext.AddLoadMessage("You must enter a name for the board."); return; } if (BoardID == null && this.CreateAdminUser.Checked) { if (this.UserName.Text.Trim().Length == 0) { PageContext.AddLoadMessage("You must enter the name of a administrator user."); return; } if (this.UserEmail.Text.Trim().Length == 0) { PageContext.AddLoadMessage("You must enter the email address of the administrator user."); return; } if (this.UserPass1.Text.Trim().Length == 0) { PageContext.AddLoadMessage("You must enter a password for the administrator user."); return; } if (this.UserPass1.Text != this.UserPass2.Text) { PageContext.AddLoadMessage("The passwords don't match."); return; } } if (BoardID != null) { System.Data.DataTable cult = StaticDataHelper.Cultures(); string langFile = "en-US"; foreach (System.Data.DataRow drow in cult.Rows) { if (drow["CultureTag"].ToString() == this.Culture.SelectedValue) { langFile = (string)drow["CultureFile"]; } } // Save current board settings DB.board_save(BoardID, langFile, this.Culture.SelectedItem.Value, this.Name.Text.Trim(), this.AllowThreaded.Checked); } else { // Create board // MEK says : Purposefully set MembershipAppName without including RolesAppName yet, as the current providers don't support different Appnames. if (this.CreateAdminUser.Checked) { CreateBoard( this.UserName.Text.Trim(), this.UserPass1.Text, this.UserEmail.Text.Trim(), this.UserPasswordQuestion.Text.Trim(), this.UserPasswordAnswer.Text.Trim(), this.Name.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), true); } else { // create admin user from logged in user... CreateBoard( null, null, null, null, null, this.Name.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), this.BoardMembershipAppName.Text.Trim(), false); } } // Done PageContext.BoardSettings = null; YafBuildLink.Redirect(ForumPages.admin_boards); }
/// <summary> /// The create board. /// </summary> /// <param name="adminName"> /// The admin name. /// </param> /// <param name="adminPassword"> /// The admin password. /// </param> /// <param name="adminEmail"> /// The admin email. /// </param> /// <param name="adminPasswordQuestion"> /// The admin password question. /// </param> /// <param name="adminPasswordAnswer"> /// The admin password answer. /// </param> /// <param name="boardName"> /// The board name. /// </param> /// <param name="boardMembershipAppName"> /// The board membership app name. /// </param> /// <param name="boardRolesAppName"> /// The board roles app name. /// </param> /// <param name="createUserAndRoles"> /// The create user and roles. /// </param> /// <exception cref="ApplicationException"> /// </exception> protected void CreateBoard( string adminName, string adminPassword, string adminEmail, string adminPasswordQuestion, string adminPasswordAnswer, string boardName, string boardMembershipAppName, string boardRolesAppName, bool createUserAndRoles) { // Store current App Names string currentMembershipAppName = PageContext.CurrentMembership.ApplicationName; string currentRolesAppName = PageContext.CurrentRoles.ApplicationName; if (boardMembershipAppName.IsSet() && boardRolesAppName.IsSet()) { // Change App Names for new board PageContext.CurrentMembership.ApplicationName = boardMembershipAppName; PageContext.CurrentMembership.ApplicationName = boardRolesAppName; } int newBoardID = 0; System.Data.DataTable cult = StaticDataHelper.Cultures(); string langFile = "english.xml"; foreach (System.Data.DataRow drow in cult.Rows) { if (drow["CultureTag"].ToString() == this.Culture.SelectedValue) { langFile = (string)drow["CultureFile"]; } } if (createUserAndRoles) { // Create new admin users MembershipCreateStatus createStatus; MembershipUser newAdmin = PageContext.CurrentMembership.CreateUser( adminName, adminPassword, adminEmail, adminPasswordQuestion, adminPasswordAnswer, true, null, out createStatus); if (createStatus != MembershipCreateStatus.Success) { PageContext.AddLoadMessage("Create User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(createStatus))); throw new ApplicationException("Create User Failed: {0}".FormatWith(this.GetMembershipErrorMessage(createStatus))); } // Create groups required for the new board RoleMembershipHelper.CreateRole("Administrators"); RoleMembershipHelper.CreateRole("Registered"); // Add new admin users to group RoleMembershipHelper.AddUserToRole(newAdmin.UserName, "Administrators"); // Create Board newBoardID = DB.board_create(newAdmin.UserName, newAdmin.Email, newAdmin.ProviderUserKey, boardName, this.Culture.SelectedItem.Value, langFile, boardMembershipAppName, boardRolesAppName); } else { // new admin MembershipUser newAdmin = UserMembershipHelper.GetUser(); // Create Board newBoardID = DB.board_create(newAdmin.UserName, newAdmin.Email, newAdmin.ProviderUserKey, boardName, this.Culture.SelectedItem.Value, langFile, boardMembershipAppName, boardRolesAppName); } if (newBoardID > 0 && Config.MultiBoardFolders) { // Successfully created the new board string boardFolder = Server.MapPath(Path.Combine(Config.BoardRoot, newBoardID.ToString() + "/")); // Create New Folders. if (!Directory.Exists(Path.Combine(boardFolder, "Images"))) { // Create the Images Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images")); // Create Sub Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Emoticons")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Ranks")); } if (!Directory.Exists(Path.Combine(boardFolder, "Themes"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Themes")); // Need to copy default theme to the Themes Folder } if (!Directory.Exists(Path.Combine(boardFolder, "Uploads"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads")); } } // Return application name to as they were before. YafContext.Current.CurrentMembership.ApplicationName = currentMembershipAppName; YafContext.Current.CurrentRoles.ApplicationName = currentRolesAppName; }
/// <summary> /// The create board. /// </summary> /// <param name="adminName">The admin name.</param> /// <param name="adminPassword">The admin password.</param> /// <param name="adminEmail">The admin email.</param> /// <param name="adminPasswordQuestion">The admin password question.</param> /// <param name="adminPasswordAnswer">The admin password answer.</param> /// <param name="boardName">The board name.</param> /// <param name="boardMembershipAppName">The board membership app name.</param> /// <param name="boardRolesAppName">The board roles app name.</param> /// <param name="createUserAndRoles">The create user and roles.</param> /// <returns>Returns if the board was created or not</returns> protected bool CreateBoard( [NotNull] string adminName, [NotNull] string adminPassword, [NotNull] string adminEmail, [NotNull] string adminPasswordQuestion, [NotNull] string adminPasswordAnswer, [NotNull] string boardName, [NotNull] string boardMembershipAppName, [NotNull] string boardRolesAppName, bool createUserAndRoles) { // Store current App Names var currentMembershipAppName = this.Get <MembershipProvider>().ApplicationName; var currentRolesAppName = this.Get <RoleProvider>().ApplicationName; if (boardMembershipAppName.IsSet() && boardRolesAppName.IsSet()) { // Change App Names for new board this.Get <MembershipProvider>().ApplicationName = boardMembershipAppName; this.Get <MembershipProvider>().ApplicationName = boardRolesAppName; } int newBoardId; var cult = StaticDataHelper.Cultures(); var langFile = "english.xml"; cult.Where(dataRow => dataRow.CultureTag == this.Culture.SelectedValue) .ForEach(row => langFile = row.CultureFile); if (createUserAndRoles) { // Create new admin users var newAdmin = this.Get <MembershipProvider>() .CreateUser( adminName, adminPassword, adminEmail, adminPasswordQuestion, adminPasswordAnswer, true, null, out var createStatus); if (createStatus != MembershipCreateStatus.Success) { this.PageContext.AddLoadMessage( $"Create User Failed: {this.GetMembershipErrorMessage(createStatus)}", MessageTypes.danger); return(false); } // Create groups required for the new board RoleMembershipHelper.CreateRole("Administrators"); RoleMembershipHelper.CreateRole("Registered"); // Add new admin users to group RoleMembershipHelper.AddUserToRole(newAdmin.UserName, "Administrators"); // Create Board newBoardId = this.DbCreateBoard( boardName, boardMembershipAppName, boardRolesAppName, langFile, newAdmin); } else { // new admin var newAdmin = UserMembershipHelper.GetUser(); // Create Board newBoardId = this.DbCreateBoard( boardName, boardMembershipAppName, boardRolesAppName, langFile, newAdmin); } if (newBoardId > 0 && Config.MultiBoardFolders) { // Successfully created the new board var boardFolder = this.Server.MapPath(Path.Combine(Config.BoardRoot, $"{newBoardId}/")); // Create New Folders. if (!Directory.Exists(Path.Combine(boardFolder, "Images"))) { // Create the Images Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images")); // Create Sub Folders Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Avatars")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Categories")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Forums")); Directory.CreateDirectory(Path.Combine(boardFolder, "Images\\Medals")); } if (!Directory.Exists(Path.Combine(boardFolder, "Uploads"))) { Directory.CreateDirectory(Path.Combine(boardFolder, "Uploads")); } } // Return application name to as they were before. this.Get <MembershipProvider>().ApplicationName = currentMembershipAppName; this.Get <RoleProvider>().ApplicationName = currentRolesAppName; return(true); }
/// <summary> /// The bind data. /// </summary> private void BindData() { this.TimeZones.DataSource = StaticDataHelper.TimeZones(); if (this.Get <YafBoardSettings>().AllowUserTheme) { this.Theme.DataSource = StaticDataHelper.Themes(); this.Theme.DataTextField = "Theme"; this.Theme.DataValueField = "FileName"; } if (this.Get <YafBoardSettings>().AllowUserLanguage) { this.Culture.DataSource = StaticDataHelper.Cultures(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; } this.Country.DataSource = StaticDataHelper.Country(); this.Country.DataValueField = "Value"; this.Country.DataTextField = "Name"; if (this.UserData.Profile.Country.IsSet()) { this.LookForNewRegionsBind(this.UserData.Profile.Country); } if (this.Get <YafBoardSettings>().AllowUsersTextEditor) { this.ForumEditor.DataSource = this.Get <IModuleManager <ForumEditor> >().ActiveAsDataTable("Editors"); this.ForumEditor.DataValueField = "Value"; this.ForumEditor.DataTextField = "Name"; } this.DataBind(); if (this.Get <YafBoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture()) { this.Birthday.Text = this.UserData.Profile.Birthday > DateTimeHelper.SqlDbMinTime() || this.UserData.Profile.Birthday.IsNullOrEmptyDBField() ? PersianDateConverter.ToPersianDate(this.UserData.Profile.Birthday) .ToString("d") : PersianDateConverter.ToPersianDate(PersianDate.MinValue).ToString("d"); } else { this.Birthday.Text = this.UserData.Profile.Birthday > DateTimeHelper.SqlDbMinTime() || this.UserData.Profile.Birthday.IsNullOrEmptyDBField() ? this.UserData.Profile.Birthday.Date.ToString( this.CurrentCultureInfo.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture) : DateTimeHelper.SqlDbMinTime() .Date.ToString( this.CurrentCultureInfo.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture); } this.Birthday.ToolTip = this.GetText("COMMON", "CAL_JQ_TT"); this.DisplayName.Text = this.UserData.DisplayName; this.City.Text = this.UserData.Profile.City; this.Location.Text = this.UserData.Profile.Location; this.HomePage.Text = this.UserData.Profile.Homepage; this.Email.Text = this.UserData.Email; this.Realname.Text = this.UserData.Profile.RealName; this.Occupation.Text = this.UserData.Profile.Occupation; this.Interests.Text = this.UserData.Profile.Interests; this.Weblog.Text = this.UserData.Profile.Blog; this.WeblogUrl.Text = this.UserData.Profile.BlogServiceUrl; this.WeblogID.Text = this.UserData.Profile.BlogServicePassword; this.WeblogUsername.Text = this.UserData.Profile.BlogServiceUsername; this.MSN.Text = this.UserData.Profile.MSN; this.YIM.Text = this.UserData.Profile.YIM; this.AIM.Text = this.UserData.Profile.AIM; this.ICQ.Text = this.UserData.Profile.ICQ; this.Facebook.Text = ValidationHelper.IsNumeric(this.UserData.Profile.Facebook) ? "https://www.facebook.com/profile.php?id={0}".FormatWith( this.UserData.Profile.Facebook) : this.UserData.Profile.Facebook; this.Twitter.Text = this.UserData.Profile.Twitter; this.Google.Text = this.UserData.Profile.Google; this.Xmpp.Text = this.UserData.Profile.XMPP; this.Skype.Text = this.UserData.Profile.Skype; this.Gender.SelectedIndex = this.UserData.Profile.Gender; if (this.UserData.Profile.Country.IsSet()) { ListItem countryItem = this.Country.Items.FindByValue(this.UserData.Profile.Country.Trim()); if (countryItem != null) { countryItem.Selected = true; } } if (this.UserData.Profile.Region.IsSet()) { ListItem regionItem = this.Region.Items.FindByValue(this.UserData.Profile.Region.Trim()); if (regionItem != null) { regionItem.Selected = true; } } ListItem timeZoneItem = this.TimeZones.Items.FindByValue(this.UserData.TimeZone.ToString()); if (timeZoneItem != null) { timeZoneItem.Selected = true; } this.DSTUser.Checked = this.UserData.DSTUser; this.HideMe.Checked = this.UserData.IsActiveExcluded && (this.Get <YafBoardSettings>().AllowUserHideHimself || this.PageContext.IsAdmin); if (this.Get <YafBoardSettings>().MobileTheme.IsSet() && UserAgentHelper.IsMobileDevice(HttpContext.Current.Request.UserAgent) || HttpContext.Current.Request.Browser.IsMobileDevice) { this.UseMobileThemeRow.Visible = true; this.UseMobileTheme.Checked = this.UserData.UseMobileTheme; } if (this.Get <YafBoardSettings>().AllowUserTheme&& this.Theme.Items.Count > 0) { // Allows to use different per-forum themes, // While "Allow User Change Theme" option in hostsettings is true string themeFile = this.Get <YafBoardSettings>().Theme; if (this.UserData.ThemeFile.IsSet()) { themeFile = this.UserData.ThemeFile; } ListItem themeItem = this.Theme.Items.FindByValue(themeFile); if (themeItem != null) { themeItem.Selected = true; } } if (this.Get <YafBoardSettings>().AllowUsersTextEditor&& this.ForumEditor.Items.Count > 0) { // Text editor string textEditor = this.UserData.TextEditor.IsSet() ? this.UserData.TextEditor : this.Get <YafBoardSettings>().ForumEditor; ListItem editorItem = this.ForumEditor.Items.FindByValue(textEditor); if (editorItem != null) { editorItem.Selected = true; } } if (!this.Get <YafBoardSettings>().AllowUserLanguage || this.Culture.Items.Count <= 0) { return; } // If 2-letter language code is the same we return Culture, else we return a default full culture from language file ListItem foundCultItem = this.Culture.Items.FindByValue(this.GetCulture(true)); if (foundCultItem != null) { foundCultItem.Selected = true; } if (!Page.IsPostBack) { this.Realname.Focus(); } }
/// <summary> /// Binds the data. /// </summary> private void BindData() { var board = this.GetRepository <Board>().GetById(this.PageContext.PageBoardID); using (var dt = new DataTable("Files")) { dt.Columns.Add("FileName", typeof(string)); dt.Columns.Add("Description", typeof(string)); var dr = dt.NewRow(); dr["FileName"] = BoardInfo.GetURLToContent("images/spacer.gif"); // use spacer.gif for Description Entry dr["Description"] = this.GetText("BOARD_LOGO_SELECT"); dt.Rows.Add(dr); var dir = new DirectoryInfo( this.Get <HttpRequestBase>() .MapPath($"{BoardInfo.ForumServerFileRoot}{BoardFolders.Current.Logos}")); var files = dir.GetFiles("*.*"); dt.AddImageFiles(files, BoardFolders.Current.Logos); this.BoardLogo.DataSource = dt; this.BoardLogo.DataValueField = "FileName"; this.BoardLogo.DataTextField = "Description"; this.BoardLogo.DataBind(); } this.Name.Text = board.Name; var boardSettings = this.Get <BoardSettings>(); this.CdvVersion.Text = boardSettings.CdvVersion.ToString(); // create list boxes by populating data sources from Data class var themeData = StaticDataHelper.Themes(); if (themeData.Any()) { this.Theme.DataSource = themeData; this.Theme.DataBind(); } this.Culture.DataSource = StaticDataHelper.Cultures().OrderBy(x => x.CultureNativeName); this.Culture.DataTextField = "CultureNativeName"; this.Culture.DataValueField = "CultureTag"; this.Culture.DataBind(); this.ShowTopic.DataSource = StaticDataHelper.TopicTimes(); this.ShowTopic.DataTextField = "Name"; this.ShowTopic.DataValueField = "Value"; this.ShowTopic.DataBind(); // population default notification setting options... var items = EnumHelper.EnumToDictionary <UserNotificationSetting>(); if (!boardSettings.AllowNotificationAllPostsAllTopics) { // remove it... items.Remove(UserNotificationSetting.AllTopics.ToInt()); } var notificationItems = items.Select( x => new ListItem( HtmlHelper.StripHtml(this.GetText("SUBSCRIPTIONS", x.Value)), x.Key.ToString())) .ToArray(); this.DefaultNotificationSetting.Items.AddRange(notificationItems); // Get first default full culture from a language file tag. var langFileCulture = StaticDataHelper.CultureDefaultFromFile(boardSettings.Language) ?? "en-US"; if (boardSettings.Theme.Contains(".xml")) { SetSelectedOnList(ref this.Theme, "yaf"); } else { SetSelectedOnList(ref this.Theme, boardSettings.Theme); } SetSelectedOnList(ref this.Culture, boardSettings.Culture); if (this.Culture.SelectedIndex == 0) { // If 2-letter language code is the same we return Culture, else we return a default full culture from language file SetSelectedOnList( ref this.Culture, langFileCulture.Substring(0, 2) == boardSettings.Culture ? boardSettings.Culture : langFileCulture); } SetSelectedOnList(ref this.ShowTopic, boardSettings.ShowTopicsDefault.ToString()); SetSelectedOnList( ref this.DefaultNotificationSetting, boardSettings.DefaultNotificationSetting.ToInt().ToString()); this.NotificationOnUserRegisterEmailList.Text = boardSettings.NotificationOnUserRegisterEmailList; this.EmailModeratorsOnModeratedPost.Checked = boardSettings.EmailModeratorsOnModeratedPost; this.EmailModeratorsOnReportedPost.Checked = boardSettings.EmailModeratorsOnReportedPost; this.AllowDigestEmail.Checked = boardSettings.AllowDigestEmail; this.DefaultSendDigestEmail.Checked = boardSettings.DefaultSendDigestEmail; this.ForumEmail.Text = boardSettings.ForumEmail; this.ForumBaseUrlMask.Text = boardSettings.BaseUrlMask; var item = this.BoardLogo.Items.FindByText(boardSettings.ForumLogo); if (item != null) { item.Selected = true; } this.CopyrightRemovalKey.Text = boardSettings.CopyrightRemovalDomainKey; this.DigestSendEveryXHours.Text = boardSettings.DigestSendEveryXHours.ToString(); // Copyright Link-back Algorithm // Please keep if you haven't purchased a removal or commercial license. this.CopyrightHolder.Visible = true; }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.IsPostBack) { return; } var boardSettings = this.Get <YafBoardSettings>(); this.PageLinks.AddLink(boardSettings.Name, YafBuildLink.GetLink(ForumPages.forum)); this.PageLinks.AddLink( this.GetText("ADMIN_ADMIN", "Administration"), YafBuildLink.GetLink(ForumPages.admin_admin)); this.PageLinks.AddLink(this.GetText("ADMIN_BOARDSETTINGS", "TITLE"), string.Empty); this.Page.Header.Title = "{0} - {1}".FormatWith( this.GetText("ADMIN_ADMIN", "Administration"), this.GetText("ADMIN_BOARDSETTINGS", "TITLE")); this.Save.Text = this.GetText("COMMON", "SAVE"); // create list boxes by populating datasources from Data class var themeData = StaticDataHelper.Themes().AsEnumerable().Where(x => !x.Field <bool>("IsMobile")); if (themeData.Any()) { this.Theme.DataSource = themeData.CopyToDataTable(); this.Theme.DataTextField = "Theme"; this.Theme.DataValueField = "FileName"; } var mobileThemeData = StaticDataHelper.Themes().AsEnumerable().Where(x => x.Field <bool>("IsMobile")); if (mobileThemeData.Any()) { var mobileThemes = mobileThemeData.CopyToDataTable(); // Add Dummy Disabled Mobile Theme Item to allow disabling the Mobile Theme DataRow dr = mobileThemes.NewRow(); dr["Theme"] = "[ {0} ]".FormatWith(this.GetText("ADMIN_COMMON", "DISABLED")); dr["FileName"] = string.Empty; dr["IsMobile"] = false; mobileThemes.Rows.InsertAt(dr, 0); this.MobileTheme.DataSource = mobileThemes; this.MobileTheme.DataTextField = "Theme"; this.MobileTheme.DataValueField = "FileName"; } this.Culture.DataSource = StaticDataHelper.Cultures() .AsEnumerable() .OrderBy(x => x.Field <string>("CultureNativeName")) .CopyToDataTable(); this.Culture.DataTextField = "CultureNativeName"; this.Culture.DataValueField = "CultureTag"; this.ShowTopic.DataSource = StaticDataHelper.TopicTimes(); this.ShowTopic.DataTextField = "TopicText"; this.ShowTopic.DataValueField = "TopicValue"; this.FileExtensionAllow.DataSource = StaticDataHelper.AllowDisallow(); this.FileExtensionAllow.DataTextField = "Text"; this.FileExtensionAllow.DataValueField = "Value"; this.JqueryUITheme.DataSource = StaticDataHelper.JqueryUIThemes(); this.JqueryUITheme.DataTextField = "Theme"; this.JqueryUITheme.DataValueField = "Theme"; this.BindData(); // bind poll group list var pollGroup = LegacyDb.PollGroupList(this.PageContext.PageUserID, null, this.PageContext.PageBoardID) .Distinct(new AreEqualFunc <TypedPollGroup>((v1, v2) => v1.PollGroupID == v2.PollGroupID)) .ToList(); pollGroup.Insert(0, new TypedPollGroup(string.Empty, -1)); // TODO: vzrus needs some work, will be in polls only until feature is debugged there. this.PollGroupListDropDown.Items.AddRange(pollGroup.Select(x => new ListItem(x.Question, x.PollGroupID.ToString())).ToArray()); // population default notification setting options... var items = EnumHelper.EnumToDictionary <UserNotificationSetting>(); if (!boardSettings.AllowNotificationAllPostsAllTopics) { // remove it... items.Remove(UserNotificationSetting.AllTopics.ToInt()); } var notificationItems = items.Select(x => new ListItem(HtmlHelper.StripHtml(this.GetText("CP_SUBSCRIPTIONS", x.Value)), x.Key.ToString())).ToArray(); this.DefaultNotificationSetting.Items.AddRange(notificationItems); SetSelectedOnList(ref this.JqueryUITheme, boardSettings.JqueryUITheme); // Get first default full culture from a language file tag. string langFileCulture = StaticDataHelper.CultureDefaultFromFile(boardSettings.Language) ?? "en-US"; SetSelectedOnList(ref this.Theme, boardSettings.Theme); SetSelectedOnList(ref this.MobileTheme, boardSettings.MobileTheme); // If 2-letter language code is the same we return Culture, else we return a default full culture from language file /* SetSelectedOnList( * ref this.Culture, * langFileCulture.Substring(0, 2) == this.Get<YafBoardSettings>().Culture * ? this.Get<YafBoardSettings>().Culture * : langFileCulture);*/ SetSelectedOnList(ref this.Culture, boardSettings.Culture); if (this.Culture.SelectedIndex == 0) { // If 2-letter language code is the same we return Culture, else we return a default full culture from language file SetSelectedOnList( ref this.Culture, langFileCulture.Substring(0, 2) == boardSettings.Culture ? boardSettings.Culture : langFileCulture); } SetSelectedOnList(ref this.ShowTopic, boardSettings.ShowTopicsDefault.ToString()); SetSelectedOnList( ref this.FileExtensionAllow, boardSettings.FileExtensionAreAllowed ? "0" : "1"); SetSelectedOnList( ref this.DefaultNotificationSetting, boardSettings.DefaultNotificationSetting.ToInt().ToString()); this.NotificationOnUserRegisterEmailList.Text = boardSettings.NotificationOnUserRegisterEmailList; this.AllowThemedLogo.Checked = boardSettings.AllowThemedLogo; this.EmailModeratorsOnModeratedPost.Checked = boardSettings.EmailModeratorsOnModeratedPost; this.EmailModeratorsOnReportedPost.Checked = boardSettings.EmailModeratorsOnReportedPost; this.AllowDigestEmail.Checked = boardSettings.AllowDigestEmail; this.DefaultSendDigestEmail.Checked = boardSettings.DefaultSendDigestEmail; this.ForumEmail.Text = boardSettings.ForumEmail; this.ForumBaseUrlMask.Text = boardSettings.BaseUrlMask; this.CopyrightRemovalKey.Text = boardSettings.CopyrightRemovalDomainKey; this.DigestSendEveryXHours.Text = boardSettings.DigestSendEveryXHours.ToString(); if (boardSettings.BoardPollID > 0) { this.PollGroupListDropDown.SelectedValue = boardSettings.BoardPollID.ToString(); } else { this.PollGroupListDropDown.SelectedIndex = 0; } this.PollGroupList.Visible = true; // Copyright Linkback Algorithm // Please keep if you haven't purchased a removal or commercial license. this.CopyrightHolder.Visible = true; }
/// <summary> /// The bind data. /// </summary> private void BindData() { this.TimeZones.DataSource = StaticDataHelper.TimeZones(); if (this.PageContext.BoardSettings.AllowUserTheme) { this.Theme.DataSource = StaticDataHelper.Themes(); this.Theme.DataTextField = "Theme"; this.Theme.DataValueField = "FileName"; } if (this.PageContext.BoardSettings.AllowUserLanguage) { this.Culture.DataSource = StaticDataHelper.Cultures(); this.Culture.DataValueField = "CultureTag"; this.Culture.DataTextField = "CultureNativeName"; } this.DataBind(); if (this.PageContext.BoardSettings.EnableDNACalendar) { this.datePicker.LocID = this.PageContext.Localization.GetText("COMMON", "CAL_JQ_CULTURE"); this.datePicker.AnotherFormatString = this.PageContext.Localization.GetText("COMMON", "CAL_JQ_CULTURE_DFORMAT"); this.datePicker.DateFormatString = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern; this.datePicker.Value = this.UserData.Profile.Birthday > DateTime.MinValue ? this.UserData.Profile.Birthday.Date : DateTime.MinValue.Date; this.datePicker.ToolTip = this.PageContext.Localization.GetText("COMMON", "CAL_JQ_TT"); this.datePicker.DefaultDateString = string.Empty; } else { this.datePicker.Enabled = false; this.datePicker.Visible = false; this.BirthdayLabel.Visible = false; } this.DisplayName.Text = this.UserData.DisplayName; this.Location.Text = this.UserData.Profile.Location; this.HomePage.Text = this.UserData.Profile.Homepage; this.Email.Text = this.UserData.Email; this.Realname.Text = this.UserData.Profile.RealName; this.Occupation.Text = this.UserData.Profile.Occupation; this.Interests.Text = this.UserData.Profile.Interests; this.Weblog.Text = this.UserData.Profile.Blog; this.WeblogUrl.Text = this.UserData.Profile.BlogServiceUrl; this.WeblogID.Text = this.UserData.Profile.BlogServicePassword; this.WeblogUsername.Text = this.UserData.Profile.BlogServiceUsername; this.MSN.Text = this.UserData.Profile.MSN; this.YIM.Text = this.UserData.Profile.YIM; this.AIM.Text = this.UserData.Profile.AIM; this.ICQ.Text = this.UserData.Profile.ICQ; this.Xmpp.Text = this.UserData.Profile.XMPP; this.Skype.Text = this.UserData.Profile.Skype; this.Gender.SelectedIndex = this.UserData.Profile.Gender; ListItem timeZoneItem = this.TimeZones.Items.FindByValue(this.UserData.TimeZone.ToString()); if (timeZoneItem != null) { timeZoneItem.Selected = true; } this.DSTUser.Checked = this.UserData.DSTUser; this.HideMe.Checked = this.UserData.IsActiveExcluded && (this.PageContext.BoardSettings.AllowUserHideHimself || this.PageContext.IsAdmin); if (YafContext.Current.BoardSettings.MobileTheme.IsSet() && UserAgentHelper.IsMobileDevice(HttpContext.Current.Request.UserAgent) || HttpContext.Current.Request.Browser.IsMobileDevice) { this.UseMobileThemeRow.Visible = true; this.UseMobileTheme.Checked = this.UserData.UseMobileTheme; } if (this.PageContext.BoardSettings.AllowUserTheme && this.Theme.Items.Count > 0) { // Allows to use different per-forum themes, // While "Allow User Change Theme" option in hostsettings is true string themeFile = this.PageContext.BoardSettings.Theme; if (!string.IsNullOrEmpty(this.UserData.ThemeFile)) { themeFile = this.UserData.ThemeFile; } ListItem themeItem = this.Theme.Items.FindByValue(themeFile); if (themeItem != null) { themeItem.Selected = true; } } if (!this.PageContext.BoardSettings.AllowUserLanguage || this.Culture.Items.Count <= 0) { return; } string languageFile = this.PageContext.BoardSettings.Language; string culture4tag = this.PageContext.BoardSettings.Culture; if (!string.IsNullOrEmpty(this.UserData.LanguageFile)) { languageFile = this.UserData.LanguageFile; } if (!string.IsNullOrEmpty(this.UserData.CultureUser)) { culture4tag = this.UserData.CultureUser; } // Get first default full culture from a language file tag. string langFileCulture = StaticDataHelper.CultureDefaultFromFile(languageFile); // If 2-letter language code is the same we return Culture, else we return a default full culture from language file ListItem foundCultItem = this.Culture.Items.FindByValue((langFileCulture.Substring(0, 2) == culture4tag.Substring(0, 2) ? culture4tag : langFileCulture)); if (foundCultItem != null) { foundCultItem.Selected = true; } }