func (this *AdminController) DoPostEdit() { id := this.GetString("post-id") post_id, err := strconv.Atoi(id) if err != nil { panic(err) } post_title := this.GetString("post-title") post_slug := this.GetString("post-slug") _, err = strconv.Atoi(post_slug) if err == nil { panic(errors.New("error: post slug should not be a number")) } post_content := this.GetString("post-content") post_content_md := this.GetString("post-content-md") if post_title == "" || post_content == "" || post_content_md == "" || post_slug == "" { panic(errors.New("error: empty post title, slug or content")) } comment_status, err := this.GetInt("comment-status", 1) if err != nil { panic(err) } post_tags := this.Input()["post-tags"] var tags []*models.Tag for _, t := range post_tags { t = strings.TrimSpace(t) tag := &models.Tag{ TagName: t, TagSlug: strings.ToLower(t), } tags = append(tags, tag) } post := models.NewPost() post.PostId = post_id post.CommentStatus = comment_status post.PostTitle = post_title post.PostSlug = post_slug post.PostContent = post_content post.PostContentMd = post_content_md post.PostModifiedTime = time.Now().Format("2006-01-02 15:04:05") post.Tags = tags err = models.NewPostModel().PostEdit(post) if err != nil { panic(err) } this.Redirect(post.PostLink(), 302) }
func (this *CommentController) DoAddComment() { if cpt.VerifyReq(this.Ctx.Request) != true { panic(errors.New("error: wrong captcha")) } content := this.GetString("comment") if content == "" { panic(errors.New("error: empty comment")) } post_id := this.Input().Get("post_id") int_post_id, _ := strconv.Atoi(post_id) if int_post_id == 0 { this.StopRun() } comment_parent_id := this.Input().Get("comment_parent_id") int_comment_parent_id, _ := strconv.Atoi(comment_parent_id) comment := models.NewComment() logged_user := this.loggedUser if logged_user != nil { comment.CommentAuthor = logged_user.DisplayName comment.CommentAuthorMail = logged_user.AuthorMail comment.CommentAuthorUrl = logged_user.AuthorUrl } else { if this.GetString("comment_author") != "" { comment.CommentAuthor = this.GetString("comment_author") } if this.GetString("comment_author_mail") != "" { comment.CommentAuthorMail = this.GetString("comment_author_mail") } if this.GetString("comment_author_url") != "" { comment.CommentAuthorUrl = this.GetString("comment_author_url") } } comment.CommentAuthorIp = this.Ctx.Input.IP() comment.CommentContent = content comment.CommentAgent = this.Ctx.Request.UserAgent() comment.CommentParentId = int_comment_parent_id post := models.NewPost() post.PostId = int_post_id comment.Post = post comment_id, err := models.NewCommentModel().AddComment(comment) if err != nil { panic(err) } if logged_user == nil { this.Ctx.SetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR, comment.CommentAuthor) this.Ctx.SetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR_MAIL, comment.CommentAuthorMail) this.Ctx.SetSecureCookie(COOKIE_SECURE_KEY_COMMENT, COOKIE_NAME_COMMENT_AUTHOR_URL, comment.CommentAuthorUrl) } ret := struct { Code int Message string Data int64 }{0, "success", comment_id} this.Data["json"] = &ret this.ServeJSON() }