//创建帖子 func (self *TopicHandler) Post() { if hash := self.GetString("hash"); hash != "" { //(decrypt bool, hash string, status string, content []byte, aesPublicKey string, rsaPublicKey []byte, rsaPrivateKey []byte) if rsa_decrypt_content, err := helper.ReceivingPackets(true, hash, "POST", self.Ctx.Input.RequestBody, aesPublicKey, rsaPublicKey, rsaPrivateKey); err == nil { tp := new(model.Topic) json.Unmarshal(rsa_decrypt_content, &tp) if tid, err := model.PostTopic(tp); err != nil { self.Data["json"] = "Post failed!" } else { self.Data["json"] = `{"TopicId:"` + strconv.Itoa(int(tid)) + `}` } self.ServeJson() } else { fmt.Println("401 Unauthorized!") self.Abort("401") } } else { fmt.Println("401 Unauthorized!") self.Abort("401") } }
func (self *NewTopicHandler) Post() { self.TplNames = "new-topic.html" flash := beego.NewFlash() nid, _ := self.GetInt("nodeid") nd, err := model.GetNode(nid) if err != nil || nid == 0 { flash.Error("节点不存在,请创建或指定正确的节点!") flash.Store(&self.Controller) return } else { cid := nd.Pid uid, _ := self.GetSession("userid").(int64) sess_username, _ := self.GetSession("username").(string) tid_title := self.GetString("title") tid_content := self.GetString("content") if tid_title != "" && tid_content != "" { tp := new(model.Topic) tp.Title = tid_title tp.Content = tid_content tp.Cid = cid tp.Nid = nid tp.Uid = uid tp.Node = nd.Title tp.Author = sess_username tp.Created = time.Now() if s, e := helper.GetBannerThumbnail(tid_content); e == nil { tp.Attachment = s } if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := helper.GetThumbnails(tid_content); e == nil { tp.Thumbnails = thumbnails tp.ThumbnailsLarge = thumbnailslarge tp.ThumbnailsMedium = thumbnailsmedium tp.ThumbnailsSmall = thumbnailssmall } if cat, err := model.GetCategory(cid); err == nil { tp.Category = cat.Title } nodezmap := &map[string]interface{}{ "topic_time": time.Now(), "topic_count": model.GetTopicCountByNid(nid), "topic_last_user_id": uid} if e := model.UpdateNode(nid, nodezmap); e != nil { fmt.Println("NewTopic model.UpdateNode errors:", e) } if tid, err := model.PostTopic(tp); err == nil { model.SetRecordforImageOnPost(tid, uid) self.Redirect("/"+strconv.Itoa(int(tid))+"/", 302) } else { flash.Error(fmt.Sprint(err)) flash.Store(&self.Controller) return } } else { flash.Error("话题标题或内容为空!") flash.Store(&self.Controller) return } } }