protected void PostMessageHandler(object sender, System.EventArgs e) { int userID = SessionAdapter.GetUserID(); // store the new message in the given thread string mailTemplate = ApplicationAdapter.GetEmailTemplate(EmailTemplate.ThreadUpdatedNotification); int messageID = ThreadManager.CreateNewMessageInThread(_thread.ThreadID, userID, meMessageEditor.MessageText, meMessageEditor.MessageTextHTML, Request.UserHostAddress.ToString(), meMessageEditor.MessageTextXML, meMessageEditor.SubscribeToThread, mailTemplate, ApplicationAdapter.GetEmailData(), CacheManager.GetSystemData().SendReplyNotifications); // invalidate forum RSS in cache ApplicationAdapter.InvalidateCachedForumRSS(_thread.ForumID); // if auditing is required, we've to do this now. if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditNewMessage)) { SecurityManager.AuditNewMessage(userID, messageID); } // invalidate forum in asp.net cache CacheManager.InvalidateCachedItem(CacheManager.ProduceCacheKey(CacheKeys.SingleForum, _thread.ForumID)); // all ok, redirect to message list int startAtMessageIndex = ThreadGuiHelper.GetStartAtMessageForGivenMessageAndThread(_thread.ThreadID, messageID, SessionAdapter.GetUserDefaultNumberOfMessagesPerPage()); if (meMessageEditor.AddAttachment) { // redirect to manage attachment form for this message Response.Redirect(string.Format("Attachments.aspx?SourceType=1&MessageID={0}", messageID), true); } else { Response.Redirect(string.Format("Messages.aspx?ThreadID={0}&StartAtMessage={1}&#{2}", _thread.ThreadID, startAtMessageIndex, messageID), true); } }
private void btnLogin_ServerClick(object sender, System.EventArgs e) { // try to authenticate the user UserEntity user = null; SecurityManager.AuthenticateResult result = SecurityManager.AuthenticateUser(tbxUserName.Value, tbxPassword.Value, out user); switch (result) { case SecurityManager.AuthenticateResult.AllOk: // authenticated // Save session cacheable data SessionAdapter.LoadUserSessionData(user); // update last visit date in db UserManager.UpdateLastVisitDateForUser(user.UserID); // done FormsAuthentication.RedirectFromLoginPage(tbxUserName.Value, chkPersistentLogin.Checked); // Audit the login action, if it was defined to be logged for this role. if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditLogin)) { SecurityManager.AuditLogin(SessionAdapter.GetUserID()); } break; case SecurityManager.AuthenticateResult.IsBanned: lblErrorMessage.Text = "You are banned. Login won't work for you."; break; case SecurityManager.AuthenticateResult.WrongUsernamePassword: lblErrorMessage.Text = "You specified a wrong User name - Password combination. Try again."; break; } }
protected void Page_Load(object sender, EventArgs e) { int attachmentID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["AttachmentID"]); MessageEntity relatedMessage = MessageGuiHelper.GetMessageWithAttachmentLogic(attachmentID); if (relatedMessage == null) { // not found Response.Redirect("default.aspx", true); } // thread has been loaded into the related message object as well. This is needed for the forum access right check if (!SessionAdapter.CanPerformForumActionRight(relatedMessage.Thread.ForumID, ActionRights.AccessForum)) { // user can't access this forum Response.Redirect("default.aspx", true); } // Check if the thread is sticky, or that the user can see normal threads started // by others. If not, the user isn't allowed to view the thread the message is in, and therefore is denied access. if ((relatedMessage.Thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(relatedMessage.Thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !relatedMessage.Thread.IsSticky) { // user can't view the thread the message is in, because: // - the thread isn't sticky // AND // - the thread isn't posted by the calling user and the user doesn't have the right to view normal threads started by others Response.Redirect("default.aspx", true); } AttachmentEntity toStream = MessageGuiHelper.GetAttachment(attachmentID); if (toStream == null) { // not found Response.Redirect("default.aspx", true); } if (!toStream.Approved && !SessionAdapter.CanPerformForumActionRight(relatedMessage.Thread.ForumID, ActionRights.ApproveAttachment)) { // the attachment hasn't been approved yet, and the caller isn't entitled to approve attachments, so deny. // approval of attachments requires to be able to load the attachment without the attachment being approved Response.Redirect("default.aspx", true); } // all set, load stream the attachment data to the browser // create header Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Type", "application/unknown"); Response.AddHeader("Content-length", toStream.Filecontents.Length.ToString()); Response.AddHeader("Content-Disposition", "attachment; filename=" + toStream.Filename.Replace(" ", "_")); Response.AddHeader("Content-Transfer-Encoding", "Binary"); // stream the data Response.BinaryWrite(toStream.Filecontents); Response.Flush(); Response.End(); }
protected void btnUnSubscribeFromThread_Click(object sender, ImageClickEventArgs e) { if (!_userMayDoBasicThreadOperations) { return; } UserManager.RemoveSingleSubscription(_thread.ThreadID, SessionAdapter.GetUserID()); Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
protected void btnThreadDone_Click(object sender, ImageClickEventArgs e) { if (!_userMayMarkThreadAsDone) { return; } // thread is re-opened, mark it as not done. ThreadManager.UnMarkThreadAsDone(_thread.ThreadID, SessionAdapter.GetUserID()); Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
protected void btnSubscribeToThread_Click(object sender, ImageClickEventArgs e) { if (!_userMayDoBasicThreadOperations) { return; } bool result = UserManager.AddThreadToSubscriptions(_thread.ThreadID, SessionAdapter.GetUserID(), null); Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
protected void btnUnbookmarkThread_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if (!_userMayDoBasicThreadOperations) { return; } // remove the bookmark on this thread. UserManager.RemoveSingleBookmark(_thread.ThreadID, SessionAdapter.GetUserID()); Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
private void Page_Load(object sender, System.EventArgs e) { // fill the page's content DataView bookmarks = UserGuiHelper.GetBookmarksAsDataView(SessionAdapter.GetUserID()); rpThreads.DataSource = bookmarks; rpThreads.DataBind(); btnRemoveChecked.Visible = (bookmarks.Count > 0); }
/// <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(object sender, System.EventArgs e) { int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]); _thread = ThreadGuiHelper.GetThread(threadID); if (_thread == null) { // not found, return to start page Response.Redirect("default.aspx"); } // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx"); } // show user IP addresses if the user has system admin rights, security admin rights or user admin rights. _showIPAddresses = (SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement) || SessionAdapter.HasSystemActionRight(ActionRights.SecurityManagement) || SessionAdapter.HasSystemActionRight(ActionRights.UserManagement)); // Get the forum entity related to the thread. Use BL class. We could have used Lazy loading, though for the sake of separation, we'll // call into the BL class. ForumEntity forum = CacheManager.GetForum(_thread.ForumID); if (forum == null) { // not found, orphaned thread, return to default page. Response.Redirect("default.aspx"); } // check if the user can view this thread. If not, don't continue. if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !_thread.IsSticky) { // can't view this thread, it isn't visible to the user Response.Redirect("default.aspx", true); } lblForumName_Header.Text = forum.ForumName; if (!Page.IsPostBack) { bool threadStartedByCurrentUser = (_thread.StartedByUserID == SessionAdapter.GetUserID()); // Get messages and bind it to the repeater control. Use the startmessage to get only the message visible on the current page. MessagesInThreadTypedList messages = ThreadGuiHelper.GetAllMessagesInThreadAsTypedList(threadID, 0, 0); rptMessages.DataSource = messages; rptMessages.DataBind(); } }
protected void btnBookmarkThread_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if (!_userMayDoBasicThreadOperations) { return; } // bookmark this thread. bool result = UserManager.AddThreadToBookmarks(SessionAdapter.GetUserID(), _thread.ThreadID); Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
protected void PostMessageHandler(object sender, System.EventArgs e) { ThreadManager.UpdateMemo(_thread.ThreadID, meMessageEditor.MessageText); if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditEditMemo)) { SecurityManager.AuditEditMemo(SessionAdapter.GetUserID(), _thread.ThreadID); } // all ok, redirect to thread list Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startAtMessage, false); }
protected void btnClaim_Click(object sender, EventArgs e) { if (!_userMayManageSupportQueueContents) { return; } // claim this thread SupportQueueManager.ClaimThread(SessionAdapter.GetUserID(), _thread.ThreadID); // done redirect to this page to refresh. Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
private void Page_Load(object sender, System.EventArgs e) { int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]); _thread = ThreadGuiHelper.GetThread(threadID); if (_thread == null) { // not found, return to default page Response.Redirect("default.aspx", true); } // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx"); } bool userMayDeleteThread = SessionAdapter.HasSystemActionRight(ActionRights.SystemWideThreadManagement); if (!userMayDeleteThread) { // doesn't have the right to delete a thread. redirect Response.Redirect("Messages.aspx?ThreadID=" + threadID, true); } // check if the user can view this thread. If not, don't continue. if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !_thread.IsSticky) { // can't view this thread, it isn't visible to the user Response.Redirect("default.aspx", true); } if (!Page.IsPostBack) { // fill the page's content ForumEntity forum = CacheManager.GetForum(_thread.ForumID); if (forum == null) { // Orphaned thread Response.Redirect("default.aspx", true); } lblForumName.Text = forum.ForumName; lblThreadSubject.Text = HttpUtility.HtmlEncode(_thread.Subject); } }
protected void PostMessageHandler(object sender, System.EventArgs e) { int userID = SessionAdapter.GetUserID(); bool result = MessageManager.UpdateEditedMessage(userID, _editMessageID, meMessageEditor.MessageText, meMessageEditor.MessageTextHTML, Request.UserHostAddress, meMessageEditor.MessageTextXML); if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditAlteredMessage)) { SecurityManager.AuditAlteredMessage(userID, _editMessageID); } // all ok, redirect to thread list int startAtMessageID = ThreadGuiHelper.GetStartAtMessageForGivenMessageAndThread(_thread.ThreadID, _editMessageID, SessionAdapter.GetUserDefaultNumberOfMessagesPerPage()); Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + startAtMessageID + "&#" + _editMessageID, false); }
/// <summary> /// Event handler for the ItemDataBound for the repeater control. Will set/reset controls inside the repeater /// template according to the user and his rights. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void rptMessages_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case ListItemType.AlternatingItem: case ListItemType.Item: // check if the thread is closed. If so, no editing nor new postings are allowed. if (!_thread.IsClosed) { HyperLink lnkEditMessage = (HyperLink)e.Item.FindControl("lnkEditMessage"); HyperLink lnkDeleteMessage = (HyperLink)e.Item.FindControl("lnkDeleteMessage"); HyperLink lnkNewMessageWQuote = (HyperLink)e.Item.FindControl("lnkNewMessageWQuote"); // editing and new messages are allowed when the rights are ok and the user isn't the AC // Check if the current message is posted by the current user bool showEditLink = _showEditMessageLink; int currentUserID = SessionAdapter.GetUserID(); if ((currentUserID == (int)((DataRowView)e.Item.DataItem)["UserID"]) && (currentUserID != 0)) { // yes. so enable editing showEditLink = true; } // you can only delete a message that's not the first message of the first thread. int currentPageNumber = HnDGeneralUtils.TryConvertToInt(lblCurrentPage.Text); bool showDeleteLink = (currentPageNumber > 1 || e.Item.ItemIndex > 0) && _showDeleteMessageLink; lnkEditMessage.Visible = showEditLink; lnkNewMessageWQuote.Visible = _showQuoteMessageLink; lnkDeleteMessage.Visible = showDeleteLink; if (showEditLink && showDeleteLink) { // enable separator lable ((Label)e.Item.FindControl("lblMessageCmdSepDeleteEdit")).Visible = true; } if ((showEditLink && _showQuoteMessageLink) || (showDeleteLink && _showQuoteMessageLink)) { // enable separator lable ((Label)e.Item.FindControl("lblMessageCmdSepEditQuote")).Visible = true; } } break; } }
private void Page_Load(object sender, System.EventArgs e) { // clear tmp results in session SessionAdapter.AddSearchTermsAndResults(string.Empty, null); // Read all accessable forums for the current user. List <int> accessableForums = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum); string[] forumIDs = Request.QueryString.GetValues("ForumID"); List <int> forumIDsToSearchIn = new List <int>(); if (forumIDs != null) { foreach (string forumIDAsString in forumIDs) { int forumID = HnDGeneralUtils.TryConvertToInt(forumIDAsString); if (accessableForums.Contains(forumID)) { forumIDsToSearchIn.Add(forumID); } } } else { // add all forums the user has access to forumIDsToSearchIn.AddRange(accessableForums); } string searchTerms = Request.QueryString.Get("SearchTerms"); if (searchTerms.Length > 1024) { searchTerms = searchTerms.Substring(0, 1024); } SearchResultTypedList results = BL.Searcher.DoSearch(searchTerms, forumIDsToSearchIn, SearchResultsOrderSetting.ForumAscending, SearchResultsOrderSetting.LastPostDateDescending, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID(), SearchTarget.MessageText); // store results in session. SessionAdapter.AddSearchTermsAndResults(searchTerms, results); // view results. Response.Redirect("SearchResults.aspx?Page=1", true); }
/// <summary> /// Handles the ItemCommand event of the rpThreads control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void rpThreads_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { switch (e.CommandName) { case "ReleaseClaim": // release a claim on the thread. SupportQueueManager.ReleaseClaimOnThread(HnDGeneralUtils.TryConvertToInt((string)e.CommandArgument)); // done, refresh Response.Redirect("SupportQueues.aspx", true); break; case "Claim": // claim the thread specified for the current user SupportQueueManager.ClaimThread(SessionAdapter.GetUserID(), HnDGeneralUtils.TryConvertToInt((string)e.CommandArgument)); // done, refresh Response.Redirect("SupportQueues.aspx", true); break; } }
private void Page_Load(object sender, System.EventArgs e) { // use the UserID from the session, so it's impossible to edit another user. _userID = SessionAdapter.GetUserID(); if (_userID <= 0) { // anonymous Response.Redirect("default.aspx"); } if (!Page.IsPostBack) { // load the user entity from the db. UserEntity user = UserGuiHelper.GetUser(_userID); // fill in the form with data lblNickname.Text = user.NickName; tbxEmailAddress.Value = user.EmailAddress; tbxIconURL.Value = user.IconURL; if (user.DateOfBirth.HasValue) { DateTime dateOfBirth = user.DateOfBirth.Value; tbxDateOfBirth.Value = dateOfBirth.Month.ToString("0#") + "/" + dateOfBirth.Day.ToString("0#") + "/" + dateOfBirth.Year.ToString("####"); } tbxOccupation.Value = user.Occupation; tbxLocation.Value = user.Location; tbxWebsite.Value = user.Website; tbxSignature.Value = user.Signature; if (user.EmailAddressIsPublic.HasValue) { chkEmailAddressIsHidden.Checked = !user.EmailAddressIsPublic.Value; } else { chkEmailAddressIsHidden.Checked = false; } chkAutoSubscribeToThread.Checked = user.AutoSubscribeToThread; tbxDefaultNumberOfMessagesPerPage.Value = user.DefaultNumberOfMessagesPerPage.ToString(); } }
private void btnRemoveChecked_Click(object sender, System.EventArgs e) { ArrayList threadIDsToRemove = new ArrayList(); // each checked bookmarked thread has to be removed from the for (int i = 0; i < rpThreads.Items.Count; i++) { CheckBox chkRemoveFromBookmarks = (CheckBox)rpThreads.Items[i].FindControl("chkRemoveFromBookmarks"); if (chkRemoveFromBookmarks.Checked) { threadIDsToRemove.Add(HnDGeneralUtils.TryConvertToInt(chkRemoveFromBookmarks.Attributes["ThreadID"])); } } if (threadIDsToRemove.Count > 0) { // remove the threads from the bookmarks. UserManager.RemoveBookmarks(threadIDsToRemove, SessionAdapter.GetUserID()); } Response.Redirect("Bookmarks.aspx"); }
/// <summary> /// Handles the ItemCommand event of the rpAttachments control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void rpAttachments_ItemCommand(object source, RepeaterCommandEventArgs e) { int attachmentID = HnDGeneralUtils.TryConvertToInt((string)e.CommandArgument); switch (e.CommandName) { case "Approve": if (_userCanApproveAttachments) { // if auditing is required, we've to do this now. if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditApproveAttachment)) { SecurityManager.AuditApproveAttachment(SessionAdapter.GetUserID(), attachmentID); } MessageManager.ModifyAttachmentApproval(attachmentID, true); } break; case "Revoke": if (_userCanApproveAttachments) { MessageManager.ModifyAttachmentApproval(attachmentID, false); } break; case "Delete": if (_userMayManageAttachments) { MessageManager.DeleteAttachment(attachmentID); } break; } phUploadResult.Visible = false; // rebind attachments. BindAttachments(); }
protected void PostMessageHandler(object sender, System.EventArgs e) { int userID = SessionAdapter.GetUserID(); int messageID = 0; // store the new message as a new thread in the current forum. bool isSticky = meMessageEditor.IsSticky; if (!_userCanCreateNormalThreads && _userCanCreateStickyThreads) { // always sticky isSticky = true; } int threadID = ForumManager.CreateNewThreadInForum(_forum.ForumID, userID, meMessageEditor.NewThreadSubject, meMessageEditor.MessageText, meMessageEditor.MessageTextHTML, isSticky, Request.UserHostAddress.ToString(), _forum.DefaultSupportQueueID, meMessageEditor.SubscribeToThread, out messageID); // invalidate forum RSS in cache ApplicationAdapter.InvalidateCachedForumRSS(_forum.ForumID); if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditNewThread)) { SecurityManager.AuditNewThread(userID, threadID); } // invalidate Forum in ASP.NET cache CacheManager.InvalidateCachedItem(CacheManager.ProduceCacheKey(CacheKeys.SingleForum, _forum.ForumID)); if (meMessageEditor.AddAttachment) { // go to attachment management. Response.Redirect(string.Format("Attachments.aspx?SourceType=2&MessageID={0}", messageID), true); } else { // all ok, redirect to thread list Response.Redirect("Threads.aspx?ForumID=" + _forum.ForumID, true); } }
/// <summary> /// Handles the ItemCommand event of the rpAttachments control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void rpAttachments_ItemCommand(object source, RepeaterCommandEventArgs e) { int attachmentID = HnDGeneralUtils.TryConvertToInt((string)e.CommandArgument); switch (e.CommandName) { case "Approve": // if auditing is required, we've to do this now. if (SessionAdapter.CheckIfNeedsAuditing(AuditActions.AuditApproveAttachment)) { SecurityManager.AuditApproveAttachment(SessionAdapter.GetUserID(), attachmentID); } MessageManager.ModifyAttachmentApproval(attachmentID, true); break; case "Delete": MessageManager.DeleteAttachment(attachmentID); break; } // done, refresh through redirect to self Response.Redirect("ApproveAttachments.aspx", 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> private void Page_Load(object sender, System.EventArgs e) { int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]); _thread = ThreadGuiHelper.GetThread(threadID); if (_thread == null) { // not found, return to default page Response.Redirect("default.aspx", true); } _startAtMessage = HnDGeneralUtils.TryConvertToInt(Request.QueryString["StartAtMessage"]); // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx", true); } // check if the user can view this thread. If not, don't continue. if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !_thread.IsSticky) { // can't view this thread, it isn't visible to the user Response.Redirect("default.aspx", true); } // Check if the current user is allowed to edit the memo if (!SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditThreadMemo)) { // is not allowed to edit the memo Response.Redirect("Messages.aspx?ThreadID=" + threadID, true); } // User may edit memo, proceed if (!Page.IsPostBack) { // fill the page's content ForumEntity forum = CacheManager.GetForum(_thread.ForumID); if (forum == null) { // Orphaned thread Response.Redirect("default.aspx", true); } lnkThreads.Text = HttpUtility.HtmlEncode(forum.ForumName); lnkThreads.NavigateUrl += "?ForumID=" + _thread.ForumID; meMessageEditor.ForumName = forum.ForumName; meMessageEditor.ThreadSubject = "Memo for thread: " + HttpUtility.HtmlEncode(_thread.Subject); lblSectionName.Text = CacheManager.GetSectionName(forum.SectionID); lnkMessages.NavigateUrl += threadID; lnkMessages.Text = HttpUtility.HtmlEncode(_thread.Subject); string memoText = _thread.Memo; memoText += string.Format("{2}[b]-----------------------------------------------------------------{2}{1} [color value=\"0000AA\"]{0}[/color] wrote:[/b] ", SessionAdapter.GetUserNickName(), DateTime.Now.ToString(@"dd-MMM-yyyy HH:mm:ss"), Environment.NewLine); meMessageEditor.OriginalMessageText = memoText; } }
private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { this.Title += ApplicationAdapter.GetSiteName(); // first time loaded, fill in properties lblUserName.Text = SessionAdapter.GetUserNickName(); HttpContext hcCurrent = HttpContext.Current; DataTable bookmarkStatistics = null; // check if user is authenticated if (hcCurrent.Request.IsAuthenticated) { lblWelcomeTextLoggedIn.Visible = true; bookmarkStatistics = UserGuiHelper.GetBookmarkStatisticsAsDataTable(SessionAdapter.GetUserID()); } else { lblWelcomeTextNotLoggedIn.Visible = true; bookmarkStatistics = new DataTable(); } // check if the user has the action right to approve attachments on some forum. If so, show the # of attachments which need approval List <int> forumsWithApprovalRight = SessionAdapter.GetForumsWithActionRight(ActionRights.ApproveAttachment); bool canApproveAttachments = ((forumsWithApprovalRight != null) && (forumsWithApprovalRight.Count > 0)); if (canApproveAttachments) { int numberOfAttachmentsToApprove = MessageGuiHelper.GetTotalNumberOfAttachmentsToApprove( SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum), SessionAdapter.GetForumsWithActionRight(ActionRights.ApproveAttachment), SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID()); if (numberOfAttachmentsToApprove > 0) { phAttachmentsToApprove.Visible = true; phAttentionRemarks.Visible = true; } } if (SessionAdapter.HasSystemActionRight(ActionRights.QueueContentManagement)) { int numberOfThreadsInSupportQueues = SupportQueueGuiHelper.GetTotalNumberOfThreadsInSupportQueues( SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum)); if (numberOfThreadsInSupportQueues > 0) { phThreadsToSupport.Visible = true; phAttentionRemarks.Visible = true; } } DateTime lastVisitDate = SessionAdapter.GetLastVisitDate(); if (SessionAdapter.IsLastVisitDateValid()) { phLastVisitDate.Visible = true; lblLastVisitDate.Text = lastVisitDate.ToString("dd-MMM-yyyy HH:mm"); } // Get all sections which possibly can be displayed. Obtain this from the cache, as it's hardly changing data, and // this page is read a lot. _sectionsToDisplay = CacheManager.GetAllSections(); // Per section, create a view with all the forumdata and filter out the forums not visible for the current user. List <int> accessableForums = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum); List <int> forumsWithThreadsFromOthers = SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers); _forumViewsPerDisplayedSection = ForumGuiHelper.GetAllAvailableForumsDataViews(_sectionsToDisplay, accessableForums, forumsWithThreadsFromOthers, SessionAdapter.GetUserID()); // filter out sections which do not have displayable forums for this user EntityView <SectionEntity> sectionsToUse = CreateFilteredSectionsCollection(); // show the sections with displayable forums, thus the displayable sections. rpSections.DataSource = sectionsToUse; rpSections.DataBind(); // get bookmarks and show them in the gui if ((bookmarkStatistics.Rows.Count <= 0) || ((bookmarkStatistics.Rows.Count == 1) && ((int)bookmarkStatistics.Rows[0][0] == 0))) { // no bookmarks yet lblAmountBookmarks.Text = "0"; lblAmountPostingsInBookmarks.Text = "0"; lblBookmarksLastPostingDate.Text = "Never"; imgIconBookmarkNoNewPosts.Visible = true; } else { lblAmountBookmarks.Text = bookmarkStatistics.Rows[0]["AmountThreads"].ToString(); lblAmountPostingsInBookmarks.Text = bookmarkStatistics.Rows[0]["AmountPostings"].ToString(); DateTime dateLastPosting = (DateTime)bookmarkStatistics.Rows[0]["LastPostingDate"]; lblBookmarksLastPostingDate.Text = dateLastPosting.ToString("dd-MMM-yyyy HH:mm"); if (dateLastPosting > lastVisitDate) { imgIconBookmarkNewPosts.Visible = true; } else { imgIconBookmarkNoNewPosts.Visible = true; } } DataTable activeThreadsStatistics = ThreadGuiHelper.GetActiveThreadsStatisticsAsDataTable(accessableForums, CacheManager.GetSystemData().HoursThresholdForActiveThreads, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID()); if (activeThreadsStatistics != null) { if ((activeThreadsStatistics.Rows.Count <= 0) || ((activeThreadsStatistics.Rows.Count == 1) && ((int)activeThreadsStatistics.Rows[0][0] == 0))) { lblAmountActiveThreads.Text = "0"; lblAmountPostingsInActiveThreads.Text = "0"; lblActiveThreadsLastPostingDate.Text = "Never"; imgIconActiveThreadsNoNewPosts.Visible = true; } else { lblAmountActiveThreads.Text = activeThreadsStatistics.Rows[0]["AmountThreads"].ToString(); lblAmountPostingsInActiveThreads.Text = activeThreadsStatistics.Rows[0]["AmountPostings"].ToString(); DateTime dateLastPosting = (DateTime)activeThreadsStatistics.Rows[0]["LastPostingDate"]; lblActiveThreadsLastPostingDate.Text = dateLastPosting.ToString("dd-MMM-yyyy HH:mm"); if (dateLastPosting > lastVisitDate) { imgIconActiveThreadsNewPosts.Visible = true; } else { imgIconActiveThreadsNoNewPosts.Visible = true; } } } } RegisterCollapseExpandClientScript(); }
/// <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(object sender, System.EventArgs e) { int forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]); bool userHasAccess = SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx"); } bool userCanCreateThreads = (SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddNormalThread) || SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddStickyThread)); // Controls are visible by default. Hide them when the user can't create threads on this forum if (!userCanCreateThreads) { lnkNewThreadBottom.Visible = false; lnkNewThreadTop.Visible = false; } // fill the page's content ForumEntity forum = CacheManager.GetForum(forumID); if (forum == null) { // not found. Response.Redirect("default.aspx"); } _forumName = forum.ForumName; if (!Page.IsPostBack) { cbxThreadListInterval.SelectedValue = forum.DefaultThreadListInterval.ToString(); string forumNameEncoded = HttpUtility.HtmlEncode(_forumName); lblForumName.Text = forumNameEncoded; lblForumName_Header.Text = HttpUtility.HtmlEncode(_forumName); lblForumDescription.Text = HttpUtility.HtmlEncode(forum.ForumDescription); lblSectionName.Text = CacheManager.GetSectionName(forum.SectionID); string newThreadURL = string.Format("{0}?ForumID={1}", lnkNewThreadTop.NavigateUrl, forumID); lnkNewThreadTop.NavigateUrl = newThreadURL; lnkNewThreadBottom.NavigateUrl = newThreadURL; if (forum.HasRSSFeed) { lnkForumRSS.NavigateUrl += string.Format("?ForumID={0}", forumID); } else { lnkForumRSS.Visible = false; litRssButtonSpacer.Visible = false; } } SystemDataEntity systemData = CacheManager.GetSystemData(); int postLimiter = HnDGeneralUtils.TryConvertToInt(cbxThreadListInterval.SelectedValue); DataView threadsView = ForumGuiHelper.GetAllThreadsInForumAsDataView(forumID, (ThreadListInterval)(byte)postLimiter, systemData.MinNumberOfThreadsToFetch, systemData.MinNumberOfNonStickyVisibleThreads, SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID()); rpThreads.DataSource = threadsView; rpThreads.DataBind(); threadsView.Dispose(); }
private void btnUpdate_ServerClick(object sender, System.EventArgs e) { if (Page.IsValid) { // user has filled in the right values, update the user's data. string nickName = string.Empty; DateTime?dateOfBirth = null; string emailAddress = string.Empty; bool emailAddressIsPublic = false; string iconURL = string.Empty; string ipNumber = string.Empty; string location = string.Empty; string occupation = string.Empty; string password = string.Empty; string signature = string.Empty; string website = string.Empty; bool autoSubscribeThreads = true; short defaultMessagesPerPage = 10; if (tbxPassword1.Value.Length > 0) { password = tbxPassword1.Value; } emailAddress = tbxEmailAddress.Value; iconURL = tbxIconURL.Value; if (tbxDateOfBirth.Value.Length > 0) { try { dateOfBirth = System.DateTime.Parse(tbxDateOfBirth.Value, CultureInfo.InvariantCulture.DateTimeFormat); } catch (FormatException) { // format exception, date invalid, ignore, will resolve to default. } } emailAddressIsPublic = !chkEmailAddressIsHidden.Checked; location = tbxLocation.Value; occupation = tbxOccupation.Value; signature = tbxSignature.Value; website = tbxWebsite.Value; //Preferences autoSubscribeThreads = chkAutoSubscribeToThread.Checked; if (tbxDefaultNumberOfMessagesPerPage.Value.Length > 0) { defaultMessagesPerPage = HnDGeneralUtils.TryConvertToShort(tbxDefaultNumberOfMessagesPerPage.Value); } bool result = UserManager.UpdateUserProfile(SessionAdapter.GetUserID(), dateOfBirth, emailAddress, emailAddressIsPublic, iconURL, location, occupation, password, signature, website, SessionAdapter.GetUserTitleID(), ApplicationAdapter.GetParserData(), autoSubscribeThreads, defaultMessagesPerPage); if (result) { // get user back and update session object. UserEntity user = UserGuiHelper.GetUser(SessionAdapter.GetUserID()); if (user != null) { SessionAdapter.AddUserObject(user); } // all ok Response.Redirect("EditProfileSuccessful.aspx", true); } } }
protected void Page_Load(object sender, EventArgs e) { int messageID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["MessageID"]); _message = MessageGuiHelper.GetMessage(messageID); if (_message == null) { // not found Response.Redirect("default.aspx", true); } _sourceType = HnDGeneralUtils.TryConvertToInt(Request.QueryString["SourceType"]); switch (_sourceType) { case 1: // new message, or message view, for now no action needed break; case 2: // new thread, for now no action needed break; default: // unknown, redirect Response.Redirect("default.aspx", true); break; } // We could have used Lazy loading here, but for the sake of separation, we use the BL method. _thread = ThreadGuiHelper.GetThread(_message.ThreadID); if (_thread == null) { // not found. Orphaned message. Response.Redirect("default.aspx", true); } _forum = CacheManager.GetForum(_thread.ForumID); if (_forum == null) { // not found. Response.Redirect("default.aspx", true); } // check if this forum accepts attachments. if (_forum.MaxNoOfAttachmentsPerMessage <= 0) { // no, so no right to be here nor is the user here via a legitimate route. Response.Redirect("default.aspx", true); } // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx", true); } // check if the user can view this thread. If not, don't continue. if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !_thread.IsSticky) { // can't view this thread, it isn't visible to the user Response.Redirect("default.aspx", true); } // Check if the current user is allowed to manage attachments of this message, and other rights. _userMayManageAttachments = ((_message.PostedByUserID == SessionAdapter.GetUserID()) || SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ManageOtherUsersAttachments)); _userCanAddAttachments = (((_message.PostedByUserID == SessionAdapter.GetUserID()) || SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ManageOtherUsersAttachments)) && SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAttachment)); _userCanApproveAttachments = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ApproveAttachment); phAttachmentLimits.Visible = _userMayManageAttachments; if (!Page.IsPostBack) { // fill the page's content lnkThreads.Text = HttpUtility.HtmlEncode(_forum.ForumName); lnkThreads.NavigateUrl += "?ForumID=" + _thread.ForumID; lblSectionName.Text = CacheManager.GetSectionName(_forum.SectionID); lnkMessages.NavigateUrl += _message.ThreadID; lnkMessages.Text = HttpUtility.HtmlEncode(_thread.Subject); lblMaxFileSize.Text = String.Format("{0} KB", _forum.MaxAttachmentSize); lblMaxNoOfAttachmentsPerMessage.Text = _forum.MaxNoOfAttachmentsPerMessage.ToString(); lnkMessage.Text += messageID.ToString(); lnkMessage.NavigateUrl += String.Format("MessageID={0}&ThreadID={1}", messageID, _thread.ThreadID); phAddNewAttachment.Visible = _userCanAddAttachments; BindAttachments(); } else { object numberOfAttachments = ViewState["numberOfAttachments"]; if (numberOfAttachments != null) { _numberOfAttachments = (int)numberOfAttachments; } } }
protected void Page_Load(object sender, EventArgs e) { // check if the calling user is able to approve attachments in 1 or more forums List <int> forumsWithApprovalRight = SessionAdapter.GetForumsWithActionRight(ActionRights.ApproveAttachment); List <int> accessableForums = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum); if (((forumsWithApprovalRight == null) || (forumsWithApprovalRight.Count <= 0)) || ((accessableForums == null) || (accessableForums.Count <= 0))) { // no, this user doesn't have the right to approve attachments or doesn't have access to any forums. Response.Redirect("default.aspx", true); } List <int> forumsWithAttachmentDeleteRight = SessionAdapter.GetForumsWithActionRight(ActionRights.ManageOtherUsersAttachments); phAttachmentDelete.Visible = ((forumsWithAttachmentDeleteRight != null) && (forumsWithAttachmentDeleteRight.Count > 0)); if (!Page.IsPostBack) { // get all attachments which aren't approved yet as a dataview. DataView allAttachmentsToApprove = MessageGuiHelper.GetAllAttachmentsToApproveAsDataView(accessableForums, forumsWithApprovalRight, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID()); rpAttachments.DataSource = allAttachmentsToApprove; rpAttachments.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> private void Page_Load(object sender, System.EventArgs e) { int userID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["UserID"]); if (!Page.IsPostBack) { UserEntity user = UserGuiHelper.GetUserWithTitleDescription(userID); if (user == null) { // not found Response.Redirect("default.aspx", true); } // fill in the content. The user's data is already html encoded (it's stored htmlencoded in the db), so // we don't need to worry to htmlencode it before it's displayed in the form. lblNickName.Text = user.NickName; bool emailAddressIsPublic = false; if (user.EmailAddressIsPublic.HasValue) { emailAddressIsPublic = user.EmailAddressIsPublic.Value; } if (emailAddressIsPublic || (SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement))) { lblEmailAddressNotPublicTxt.Visible = false; lnkEmailAddress.Visible = true; lnkEmailAddress.NavigateUrl = "mailto:" + user.EmailAddress; lnkEmailAddress.Text = user.EmailAddress; } else { lblEmailAddressNotPublicTxt.Visible = true; } // view admin section if the user has system admin rights, security management rights, or user management rights. phAdminSection.Visible = (SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement) || SessionAdapter.HasSystemActionRight(ActionRights.SecurityManagement) || SessionAdapter.HasSystemActionRight(ActionRights.UserManagement)); if (!string.IsNullOrEmpty(user.IconURL)) { // show icon string sURL = "http://" + user.IconURL; imgIcon.ImageUrl = sURL; imgIcon.Visible = true; lblIconURL.Text = sURL; } if (user.LastVisitedDate.HasValue) { lblLastVisitDate.Text = user.LastVisitedDate.Value.ToString("dd-MMM-yyy HH:mm.ss"); } else { lblLastVisitDate.Text = "Unknown (tracked by cookie)"; } if (user.DateOfBirth.HasValue) { lblDateOfBirth.Text = user.DateOfBirth.Value.ToString("dd-MMM-yyyy"); } lblOccupation.Text = user.Occupation; lblLocation.Text = user.Location; if (!string.IsNullOrEmpty(user.Website)) { string sURL = "http://" + user.Website; lnkWebsite.Text = sURL; lnkWebsite.NavigateUrl = sURL; lnkWebsite.Visible = true; } lblSignature.Text = user.SignatureAsHTML; lblRegisteredOn.Text = user.JoinDate.Value.ToString("dd-MMM-yyyy HH:mm:ss"); lblAmountOfPosts.Text = user.AmountOfPostings.ToString(); lblUserTitle.Text = user.UserTitle.UserTitleDescription; lblIpAddress.Text = user.IPNumber; // get the last 25 threads. DataView lastThreads = UserGuiHelper.GetLastThreadsForUserAsDataView(SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum), userID, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID(), 25); rpThreads.DataSource = lastThreads; rpThreads.DataBind(); } }
private void Page_Load(object sender, System.EventArgs e) { // fill the page's content List <int> accessableForums = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum); DataView activeThreads = ThreadGuiHelper.GetActiveThreadsAsDataView(accessableForums, CacheManager.GetSystemData().HoursThresholdForActiveThreads, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID()); rpThreads.DataSource = activeThreads; rpThreads.DataBind(); }