/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that threw event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void gridElem_OnAction(string actionName, object actionArgument) { int subscriptionId = ValidationHelper.GetInteger(actionArgument, 0); switch (actionName.ToLowerCSafe()) { case "delete": if (RaiseOnCheckPermissions(PERMISSION_MANAGE, this)) { if (StopProcessing) { return; } } try { // Try to delete notification subscription BlogPostSubscriptionInfoProvider.DeleteBlogPostSubscriptionInfo(subscriptionId); } catch (Exception ex) { ShowError(ex.Message); } break; case "approve": if (RaiseOnCheckPermissions(PERMISSION_MANAGE, this)) { if (StopProcessing) { return; } } // Approve BlogPostSubscriptionInfo object BlogPostSubscriptionInfo bsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(subscriptionId); if ((bsi != null) && !bsi.SubscriptionApproved) { bsi.SubscriptionApproved = true; BlogPostSubscriptionInfoProvider.SetBlogPostSubscriptionInfo(bsi); // Log activity if (MembershipContext.AuthenticatedUser.UserID == UserID) { Service <ICurrentContactMergeService> .Entry().UpdateCurrentContactEmail(bsi.SubscriptionEmail, MembershipContext.AuthenticatedUser); var blogsActivityLogger = new BlogsActivityLogger(); blogsActivityLogger.LogBlogPostSubscriptionActivity(bsi); } } break; } }
/// <summary> /// OK click handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check banned IP if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } // Check input fields string email = txtEmail.Text.Trim(); string result = new Validator() .NotEmpty(email, rfvEmailRequired.ErrorMessage) .MatchesCondition(txtEmail, input => input.IsValid(), GetString("general.correctemailformat")) .Result; // Try to subscribe new subscriber if (result == String.Empty) { if (DocumentID > 0) { BlogPostSubscriptionInfo bpsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(email, DocumentID); // Check for duplicity of subscriptions if ((bpsi == null) || !bpsi.SubscriptionApproved) { bpsi = new BlogPostSubscriptionInfo(); bpsi.SubscriptionPostDocumentID = DocumentID; bpsi.SubscriptionEmail = email; // Update user id for logged users (except the public users) if ((MembershipContext.AuthenticatedUser != null) && (!MembershipContext.AuthenticatedUser.IsPublic())) { bpsi.SubscriptionUserID = MembershipContext.AuthenticatedUser.UserID; } BlogPostSubscriptionInfoProvider.Subscribe(bpsi, DateTime.Now, true, true); lblInfo.Visible = true; if (bpsi.SubscriptionApproved) { lblInfo.Text = GetString("blog.subscription.beensubscribed"); Service.Resolve <ICurrentContactMergeService>().UpdateCurrentContactEmail(bpsi.SubscriptionEmail, MembershipContext.AuthenticatedUser); var blogsActivityLogger = new BlogsActivityLogger(); blogsActivityLogger.LogBlogPostSubscriptionActivity(bpsi); } else { lblInfo.Text = GetString("general.subscribed.doubleoptin"); int optInInterval = BlogHelper.GetBlogDoubleOptInInterval(SiteContext.CurrentSiteName); if (optInInterval > 0) { lblInfo.Text += "<br />" + string.Format(GetString("general.subscription_timeintervalwarning"), optInInterval); } } // Clear form after successful subscription txtEmail.Text = ""; } else { result = GetString("blog.subscription.emailexists"); } } else { result = GetString("general.invalidid"); } } if (result == String.Empty) { return; } lblError.Visible = true; lblError.Text = result; }
public void PerformAction() { // Check banned ip if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } if (OnBeforeCommentSaved != null) { OnBeforeCommentSaved(); } // Validate form string errorMessage = ValidateForm(); if (errorMessage == String.Empty) { // Check flooding when message being inserted through the LiveSite if (IsLiveSite && FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { lblError.Visible = true; lblError.Text = GetString("General.FloodProtection"); return; } var currentUser = MembershipContext.AuthenticatedUser; // Create new comment BlogCommentInfo bci; if (IsInsertMode) { bci = new BlogCommentInfo(); bci.CommentDate = DateTime.Now; bci.CommentPostDocumentID = mPostDocumentId; // User IP address bci.CommentInfo.IPAddress = RequestContext.UserHostAddress; // User agent bci.CommentInfo.Agent = Request.UserAgent; if (!currentUser.IsPublic()) { bci.CommentUserID = currentUser.UserID; } } // Get existing comment else { bci = BlogCommentInfoProvider.GetBlogCommentInfo(mCommentId); } // Update basic comment properties if (bci != null) { // Add http:// if needed string url = txtUrl.Text.Trim(); if (!String.IsNullOrEmpty(url)) { string protocol = URLHelper.GetProtocol(url); if (String.IsNullOrEmpty(protocol)) { url = "http://" + url; } } bci.CommentIsSpam = chkSpam.Checked; bci.CommentApproved = chkApproved.Checked; bci.CommentUserName = txtName.Text.Trim(); bci.CommentUrl = url; bci.CommentText = txtComments.Text.Trim(); bci.CommentUrl = bci.CommentUrl.ToLowerCSafe().Replace("javascript", "_javascript"); bci.CommentEmail = txtEmail.Text.Trim(); } if (IsInsertMode) { // Auto approve owner comments if (bci != null) { TreeNode blogNode = BlogHelper.GetParentBlog(bci.CommentPostDocumentID, false); if ((currentUser != null) && (blogNode != null)) { bool isAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode); if (isAuthorized) { bci.CommentApprovedByUserID = blogNode.NodeOwner; bci.CommentApproved = true; } else { // Is blog moderated ? bool moderated = ValidationHelper.GetBoolean(blogNode.GetValue("BlogModerateComments"), false); bci.CommentApprovedByUserID = 0; bci.CommentApproved = !moderated; } } } } // Perform bad words check if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName)) { if (bci != null) { // Prepare columns to check Dictionary <string, int> columns = new Dictionary <string, int>(); columns.Add("CommentText", 0); columns.Add("CommentUserName", 200); // Perform bad words to check errorMessage = BadWordsHelper.CheckBadWords(bci, columns, "CommentApproved", "CommentApprovedByUserID", bci.CommentText, MembershipContext.AuthenticatedUser.UserID, () => ValidateComment(bci)); } } if (errorMessage == String.Empty) { if (bci != null) { if (!ValidateComment(bci)) { // Show error message lblError.Visible = true; lblError.Text = GetString("Blog.CommentEdit.EmptyBadWord"); } else { // Subscribe new subscriber var currentContactMergeService = Service.Resolve <ICurrentContactMergeService>(); if (chkSubscribe.Checked) { // Check for duplicate subscriptions BlogPostSubscriptionInfo bpsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(txtEmail.Text, mPostDocumentId); if ((bpsi == null) || !bpsi.SubscriptionApproved) { bpsi = new BlogPostSubscriptionInfo(); bpsi.SubscriptionEmail = txtEmail.Text; bpsi.SubscriptionPostDocumentID = mPostDocumentId; bpsi.SubscriptionUserID = bci.CommentUserID; BlogPostSubscriptionInfoProvider.Subscribe(bpsi, DateTime.Now, true, true); if (bpsi.SubscriptionApproved) { currentContactMergeService.UpdateCurrentContactEmail(bpsi.SubscriptionEmail, MembershipContext.AuthenticatedUser); mBlogsActivityLogger.LogBlogPostSubscriptionActivity(bpsi); } } else { errorMessage = GetString("blog.subscription.emailexists"); } } if (errorMessage == String.Empty) { // Save changes to database BlogCommentInfoProvider.SetBlogCommentInfo(bci); if (!bci.CommentApproved) { CommentSavedText = GetString("blog.comments.requiresmoderationafteraction"); } // Inform user lblInfo.Visible = true; lblInfo.Text = CommentSavedText; // Clear form when required if (mClearFormAfterSave) { txtComments.Text = String.Empty; txtUrl.Text = String.Empty; ctrlCaptcha.Value = String.Empty; } currentContactMergeService.UpdateCurrentContactEmail(bci.CommentEmail, MembershipContext.AuthenticatedUser); mBlogsActivityLogger.LogBlogCommentActivity(bci); if (OnAfterCommentSaved != null) { OnAfterCommentSaved(bci); } } } } } } if (errorMessage != "") { // Show error message lblError.Visible = true; lblError.Text = errorMessage; } }
/// <summary> /// Check that subscription hash is valid and subscription didn't expire /// </summary> /// <param name="subscriptionHash">Subscription hash to check</param> /// <param name="requestTime">Date time of subscription request</param> /// <param name="checkOnly">Indicates if only check will be performed</param> private void CheckAndSubscribe(string subscriptionHash, string requestTime, bool checkOnly) { // Get date and time DateTime datetime = DateTimeHelper.ZERO_TIME; // Get date and time if (!string.IsNullOrEmpty(requestTime)) { try { datetime = DateTimeUrlFormatter.Parse(requestTime); } catch { DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_failed"))); return; } } // Initialize opt-in result OptInApprovalResultEnum result; // Check only data consistency if (checkOnly) { // Validate hash result = BlogPostSubscriptionInfoProvider.ValidateHash(SubscriptionObject, subscriptionHash, SiteContext.CurrentSiteName, datetime); if ((result == OptInApprovalResultEnum.Success) && (SubscriptionObject.SubscriptionApproved)) { result = OptInApprovalResultEnum.NotFound; } } else { // Try to approve subscription result = BlogPostSubscriptionInfoProvider.ApproveSubscription(SubscriptionObject, subscriptionHash, false, SiteContext.CurrentSiteName, datetime); } // Process result switch (result) { // Approving subscription was successful case OptInApprovalResultEnum.Success: if (!checkOnly) { ShowInfo(DataHelper.GetNotEmpty(SuccessfulConfirmationText, GetString("general.subscription_approval"))); Service.Resolve <ICurrentContactMergeService>().UpdateCurrentContactEmail(SubscriptionObject.SubscriptionEmail, MembershipContext.AuthenticatedUser); var blogsActivityLogger = new BlogsActivityLogger(); blogsActivityLogger.LogBlogPostSubscriptionActivity(SubscriptionObject, QueryHelper.GetInteger("cid", 0), QueryHelper.GetInteger("siteid", 0), QueryHelper.GetText("camp", "")); } break; // Subscription was already approved case OptInApprovalResultEnum.Failed: DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_failed"))); break; case OptInApprovalResultEnum.TimeExceeded: BlogPostSubscriptionInfoProvider.DeleteBlogPostSubscriptionInfo(SubscriptionObject); DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_timeexceeded"))); break; // Subscription not found default: DisplayError(DataHelper.GetNotEmpty(UnsuccessfulConfirmationText, GetString("general.subscription_invalid"))); break; } }