示例#1
0
func (self *ViewHandler) Get() {
	name := self.GetString(":name")
	id, _ := self.GetInt(":id")

	if name != "" && id > 0 {
		if name == "topic" {

			if tp, err := model.GetTopic(id); tp != nil && err == nil {
				tp.Views = tp.Views + 1
				tp.Hotup = tp.Hotup + 1
				tp.Hotscore = helper.Hotness_Score(tp.Hotup, tp.Hotdown)
				tp.Hotness = helper.Hotness(tp.Hotup, tp.Hotdown, time.Now())

				if row, e := model.PutTopic(id, tp); e != nil {
					fmt.Println("ViewHandler更新话题ID", id, "访问次数数据错误,row:", row, e)
					self.Abort("500")
				} else {
					self.Ctx.Output.Context.WriteString(strconv.Itoa(int(tp.Views)))
				}
			}
		} else {
			self.Abort("501")
		}

	} else {
		self.Abort("501")
	}

}
示例#2
0
//更新帖子
func (self *TopicHandler) Put() {

	if hash := self.GetString("hash"); hash != "" {

		if rsa_decrypt_content, err := helper.ReceivingPackets(true, hash, "PUT", self.Ctx.Input.RequestBody, aesPublicKey, rsaPublicKey, rsaPrivateKey); err == nil {

			tid, _ := self.GetInt(":objectId")
			tp := new(model.Topic)
			json.Unmarshal(rsa_decrypt_content, &tp)

			if _, err := model.PutTopic(tid, tp); err != nil {
				self.Data["json"] = "Update failed!"
			} else {
				self.Data["json"] = "Update success!"
			}
			self.ServeJson()
		} else {

			fmt.Println("401 Unauthorized!")
			self.Abort("401")
		}
	} else {

		fmt.Println("401 Unauthorized!")
		self.Abort("401")
	}
}
示例#3
0
文件: EditTopic.go 项目: rose312/mzr
func (self *EditTopicHandler) Post() {
	self.TplNames = "edit-topic.html"
	flash := beego.NewFlash()

	tid, _ := self.GetInt(":tid")
	nid, _ := self.GetInt("nodeid")

	if nd, err := model.GetNode(nid); nd != nil && err == nil {

		uid, _ := self.GetSession("userid").(int64)
		tid_title := self.GetString("title")
		tid_content := self.GetString("content")

		if tid_title != "" && tid_content != "" {

			if tp, err := model.GetTopic(tid); tp != nil && err == nil {

				tp.Title = tid_title
				tp.Uid = uid

				//删去用户没再使用的图片
				helper.DelLostImages(tp.Content, tid_content)
				tp.Content = tid_content

				if s, e := helper.GetBannerThumbnail(tid_content); e == nil {
					tp.Attachment = s
				}

				if cat, err := model.GetCategory(nd.Pid); err == nil {
					tp.Category = cat.Title
				}

				if row, err := model.PutTopic(tid, tp); row == 1 && err == nil {
					model.SetRecordforImageOnEdit(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
			}
		} else {

			flash.Error("话题标题或内容为空!")
			flash.Store(&self.Controller)
			return
		}
	} else {
		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
示例#4
0
func (self *HateHandler) Get() {

	if helper.IsSpider(self.Ctx.Request.UserAgent()) != true {
		name := self.GetString(":name")
		id, _ := self.GetInt(":id")

		if name == "topic" {

			tp, _ := model.GetTopic(id)
			tp.Hotdown = tp.Hotdown + 1
			tp.Hotscore = helper.Hotness_Score(tp.Hotup, tp.Hotdown)
			tp.Hotness = helper.Hotness(tp.Hotup, tp.Hotdown, time.Now())

			model.PutTopic(id, tp)
			self.Ctx.WriteString(strconv.Itoa(int(tp.Hotscore)))

		} else if name == "timeline" {

			tl, _ := model.GetTimeline(id)
			tl.Hotdown = tl.Hotdown + 1
			tl.Hotscore = helper.Hotness_Score(tl.Hotup, tl.Hotdown)
			tl.Hotness = helper.Hotness(tl.Hotup, tl.Hotdown, time.Now())

			model.PutTimeline(id, tl)
			self.Ctx.WriteString(strconv.Itoa(int(tl.Hotscore)))

		} else if name == "node" {

			nd, _ := model.GetNode(id)
			nd.Hotdown = nd.Hotdown + 1
			nd.Hotscore = helper.Hotness_Score(nd.Hotup, nd.Hotdown)
			nd.Hotness = helper.Hotness(nd.Hotup, nd.Hotdown, time.Now())

			model.PutNode(id, nd)

			self.Ctx.WriteString("node hated")
		} else {
			self.Abort("401")
		}

	} else {
		self.Abort("401")
	}

}