//public string PostImage { get; set; } = ""; protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null && Request.Cookies["perm"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { if (!IsPostBack) { preBodyHolder.InnerText = "<p><p/> <p><p/> <p><p/> <p><p/> <p><p/>"; } try { foreach (var i in CategoryService.GetAllCategories()) { CategoryCheckBox newCategoryCheckBox = new CategoryCheckBox(i.CategoryName, i.Id); CategoryCheckBoxPanel.Controls.Add(newCategoryCheckBox); } } catch (Exception ex) { LabelMes.ForeColor = Color.Red; LabelMes.Text = ex.Message; } } //else //{ // return; //} } else { Response.Redirect("~/MainPage.aspx"); } }
protected void CommentGridview_OnRowUpdating(object sender, GridViewUpdateEventArgs e) { if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { try { HtmlTextArea commentArea = (HtmlTextArea)CommentGridview.Rows[e.RowIndex].FindControl("EditCommentTextArea"); HiddenField hfCommentId = (HiddenField)CommentGridview.Rows[e.RowIndex].FindControl("CommentId"); CommentService.UpdateComment(new CommentDto { Id = Convert.ToInt32(hfCommentId.Value), CommentText = commentArea.Value }); BindDataCommentList(); } catch (Exception ex) { LabelCommentUser.Text = ex.Message; } } } }
protected void ButtonSignIn_OnClick(object sender, EventArgs e) { try { BlogUserDto bloguserDto = new BlogUserDto { UserName = textboxUserName.Text, UserPassword = textboxPassword.Text, BlogName = textboxUserName.Text }; BlogUserService.CreateBlogUser(bloguserDto); HttpCookie login = new HttpCookie("login", bloguserDto.UserName); HttpCookie sign = new HttpCookie("sign", SignGenerator.GetSign(bloguserDto.UserName + "byte")); try { BlogUserService.GetAdminPermission(bloguserDto.UserName); HttpCookie perm = new HttpCookie("perm", "admin"); Response.Cookies.Add(perm); } catch (Exception) { } Response.Cookies.Add(login); Response.Cookies.Add(sign); Response.Redirect("~/MainPage.aspx"); } catch (Exception ex) { LabelMes.Text = ex.Message; } }
protected void CommentGridview_OnRowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Reply") { int index = Convert.ToInt32(e.CommandArgument); if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { try { HiddenField hfCommentId = (HiddenField)CommentGridview.Rows[index].FindControl("CommentId"); HtmlTextArea textareaReply = (HtmlTextArea)CommentGridview.Rows[index].FindControl("ReplyTextArea"); CommentService.CreateComment(new CommentDto { CommentText = textareaReply.InnerText, UserName = Request.Cookies["login"].Value, ParentId = Convert.ToInt32(hfCommentId.Value) }, Convert.ToInt32(Request.QueryString["PostId"])); BindDataCommentList(); } catch (Exception ex) { LabelCommentUser.Text = ex.Message; } } } } }
protected void ButtonPostComment_OnClick(object sender, EventArgs e) { if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { try { CommentService.CreateComment(new CommentDto { CommentText = CommentTextArea.Value, UserName = Request.Cookies["login"].Value }, Convert.ToInt32(Request.QueryString["PostId"])); BindDataCommentList(); CommentTextArea.InnerText = string.Empty; //Server.TransferRequest(Request.Url.AbsolutePath, false); } catch (Exception ex) { servermessageboxtext.InnerText = ex.Message; servermessagebox.Visible = true; } } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null && Request.Cookies["perm"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { try { CategoryList.Items.Clear(); foreach (var i in CategoryService.GetAllCategories()) { CategoryList.Items.Add(new ListItem(i.CategoryName, i.Id.ToString())); } } catch (Exception ex) { LabelMes.ForeColor = Color.Red; LabelMes.Text = ex.Message; } } //else //{ // //return; //} } else { Response.Redirect("~/MainPage.aspx"); } //----------------Заполняем список категорий с помощью метода GetCategories---------------------- }
protected void AuthForm_OnAuthenticate(object sender, AuthenticateEventArgs e) { try { BlogUserDto bloguserDto = new BlogUserDto(); bloguserDto.UserName = AuthForm.UserName; bloguserDto.UserPassword = AuthForm.Password; BlogUserDto newbloguserDto = BlogUserService.GetBlogUserNameAndPassword(bloguserDto); HttpCookie login = new HttpCookie("login", newbloguserDto.UserName); HttpCookie sign = new HttpCookie("sign", SignGenerator.GetSign(newbloguserDto.UserName + "byte")); try { BlogUserService.GetAdminPermission(newbloguserDto.UserName); HttpCookie perm = new HttpCookie("perm", "admin"); Response.Cookies.Add(perm); } catch (Exception) { } Response.Cookies.Add(login); Response.Cookies.Add(sign); e.Authenticated = true; } catch (Exception) { e.Authenticated = false; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDataCommentList(); if (Request.QueryString["PostId"] != null) { PostDto post = PostService.GetPost(Convert.ToInt32(Request.QueryString["PostId"])); if (File.Exists(MapPath("Images/" + post.PostImage.Trim()))) { imgpostview.Src = @"/Images/" + post.PostImage.Trim(); } PostTitle.InnerText = post.Title; divBodyHolder.InnerHtml = HttpUtility.HtmlDecode(post.Body); labelDate.Text = post.CreationDate.ToString("yyyy MMMM dd"); IEnumerable <CategoryDto> postcategories = CategoryService.GetPostCategories(Convert.ToInt32(Request.QueryString["PostId"])); string categoryString = ""; foreach (CategoryDto category in postcategories) { categoryString += category.CategoryName + ", "; } if (categoryString.Trim() != "") { categoryString = categoryString.Remove(categoryString.Length - 2); } if (categoryString == "") { categoryString = "Without category"; } markPostCategories.InnerText = "Categories: " + categoryString; } } if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { ButtonPostComment.Visible = true; ButtonPostComment.Text = "Post as " + Request.Cookies["login"].Value; LabelCommentUser.Text = "You signed in as " + Request.Cookies["login"].Value; if (Request.Cookies["perm"] != null) { ButtonChangePost.Visible = true; } } } }
protected void Page_Load(object sender, EventArgs e) { //if (Request.QueryString["user"]=="admin") //{ if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { AuthForm.Visible = false; } } else { AuthForm.Visible = true; } //} if (!IsPostBack) { List <CategoryDto> categories = (List <CategoryDto>)CategoryService.GetBlogCategories("admin"); foreach (CategoryDto category in categories) { ListItem listitem = new ListItem(category.CategoryName, category.Id.ToString()); CategoryList.Items.Add(listitem); } foreach (ListItem categoryItem in CategoryList.Items) { if (categoryItem.Value == Request.QueryString["category"]) { categoryItem.Attributes["Class"] = "activeitem"; } } } if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { LabelUserName.Text = Request.Cookies["login"].Value; LogoutPanel.Visible = true; if (Request.Cookies["perm"] != null) { adminpanel.Visible = true; } } } }
protected void ButtonChangePassword_OnClick(object sender, EventArgs e) { if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { try { BlogUserService.ChangePassword(new BlogUserDto { UserName = Request.Cookies["login"].Value, UserPassword = textboxNewPassword.Text }); Response.Redirect("~/MainPage.aspx"); } catch (Exception ex) { LabelMes.Text = ex.Message; } } } }
protected void ButtonLogin_Click(object sender, EventArgs e) { try { BlogUserDto bloguserDto = new BlogUserDto(); bloguserDto.UserName = this.TextboxLogin.Text; bloguserDto.UserPassword = this.PasswordBox.Value; BlogUserDto newbloguserDto = BlogUserService.GetBlogUserNameAndPassword(bloguserDto); HttpCookie login = new HttpCookie("login", newbloguserDto.UserName); HttpCookie sign = new HttpCookie("sign", SignGenerator.GetSign(newbloguserDto.UserName + "byte")); Response.Cookies.Add(login); Response.Cookies.Add(sign); Response.Redirect("~/MainPage.aspx"); } catch (Exception ex) { this.PasswordHelp.Text = ex.Message; } }
protected void CommentGridview_OnRowDataBound(object sender, GridViewRowEventArgs e) { BindDataDependentCommentList((GridView)e.Row.FindControl("DependentCommentGridview")); if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { if ((HtmlGenericControl)e.Row.FindControl("CommentUserName") != null) { HtmlButton openreplyButton = (HtmlButton)e.Row.FindControl("openReplyForm"); openreplyButton.Visible = true; Label userMessageReply = (Label)e.Row.FindControl("LabelCommentUserReply"); userMessageReply.Text = "You signed in as " + Request.Cookies["login"].Value; LinkButton replyButton = (LinkButton)e.Row.FindControl("ButtonReply"); replyButton.Text = "Post as " + Request.Cookies["login"].Value; HtmlTextArea replyTextArea = (HtmlTextArea)e.Row.FindControl("ReplyTextArea"); replyTextArea.InnerText = ((HtmlGenericControl)e.Row.FindControl("CommentUserName")).InnerText + ", "; HtmlGenericControl userNameLabel = (HtmlGenericControl)e.Row.FindControl("CommentUserName"); if (userNameLabel.InnerText == Request.Cookies["login"].Value) { LinkButton deleteButton = (LinkButton)e.Row.FindControl("openDeleteCommentModal"); deleteButton.Visible = true; HtmlButton editButton = (HtmlButton)e.Row.FindControl("openEditForm"); editButton.Visible = true; Label userMessage = (Label)e.Row.FindControl("LabelCommentUserEdit"); userMessage.Text = "You signed in as " + Request.Cookies["login"].Value; } } } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["login"] != null && Request.Cookies["sign"] != null && Request.Cookies["perm"] != null) { if (Request.Cookies["sign"].Value == SignGenerator.GetSign(Request.Cookies["login"].Value + "byte")) { if (!IsPostBack) { try { PostDto updatedPost = PostService.GetPost(Convert.ToInt32(Request.QueryString["PostId"])); textboxPostTitle.Text = updatedPost.Title; preBodyHolder.InnerText = HttpUtility.HtmlDecode(updatedPost.Body); } catch (Exception ex) { LabelMes.ForeColor = Color.Red; LabelMes.Text = ex.Message; } } try { //------------------Заполняем список категорий поста--------------------------- foreach (var i in CategoryService.GetAllCategories()) { int isEquals = 0; foreach (var j in (List <CategoryDto>)CategoryService.GetPostCategories(Convert.ToInt32(Request.QueryString["PostId"]))) { if (i.Id == j.Id) { isEquals = 1; } } if (isEquals == 1) { CategoryCheckBox newCategoryCheckBox = new CategoryCheckBox(i.CategoryName, i.Id, true); CategoryCheckBoxPanel.Controls.Add(newCategoryCheckBox); } else { CategoryCheckBox newCategoryCheckBox = new CategoryCheckBox(i.CategoryName, i.Id); CategoryCheckBoxPanel.Controls.Add(newCategoryCheckBox); } } } catch (Exception ex) { LabelMes.ForeColor = Color.Red; LabelMes.Text = ex.Message; } } //else //{ // return; //} } else { Response.Redirect("~/MainPage.aspx"); } }