Beispiel #1
0
func (self *EditAnswerHandler) Post() {
	self.TplNames = "sdc/edit-answer.html"

	flash := beego.NewFlash()

	aid, _ := self.GetInt(":aid")

	if aid_handler, err := model.GetAnswer(aid); err == nil {
		uid, _ := self.GetSession("userid").(int64)
		role, _ := self.GetSession("userrole").(int64)
		allow := bool(false)

		if aid_handler.Uid == uid && aid_handler.Id == aid {
			allow = true
		} else if role < 0 {
			allow = true
		}

		if allow {
			self.Data["answer"] = *aid_handler
			aid_content := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))

			if aid_content != "" {

				if anz, err := model.GetAnswer(aid); anz != nil && err == nil {

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

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

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

					anz.Updated = time.Now()

					if row, err := model.PutAnswer(aid, anz); row == 1 && err == nil {
						model.SetRecordforImageOnEdit(aid, anz.Uid)
						self.Redirect("/"+strconv.Itoa(int(anz.Pid))+"/#answer-"+strconv.Itoa(int(aid)), 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 {
			//没有权限执行该操作则直接跳转到登录页面
			self.Redirect("/user/signin/", 302)
		}

	} else {

		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}

}
Beispiel #2
0
func (self *HateHandler) Get() {

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

		if name == "question" {
			if model.IsQuestionMark(uid, id) {
				//self.Abort("304") <-白痴函数 妈的 难道这货不是用来设置状态号的?居然尼玛的直接panic!
				self.Ctx.Output.SetStatus(304)
				return

			} else {
				if qs, err := model.GetQuestion(id); err == nil {

					qs.Hotdown = qs.Hotdown + 1
					qs.Hotscore = helper.Qhot_QScore(qs.Hotup, qs.Hotdown)
					qs.Hotvote = helper.Qhot_Vote(qs.Hotup, qs.Hotdown)
					qs.Hotness = helper.Qhot(qs.Views, qs.ReplyCount, qs.Hotscore, model.GetAScoresByPid(id), qs.Created, qs.ReplyTime)

					if _, err := model.PutQuestion(id, qs); err != nil {
						fmt.Println("PutQuestion执行错误:", err)
					} else {
						model.SetQuestionMark(uid, id)
					}
					self.Ctx.WriteString(strconv.Itoa(int(qs.Hotscore)))
				} else {
					return
				}
			}
		} else if name == "answer" {
			if model.IsAnswerMark(uid, id) {
				self.Ctx.Output.SetStatus(304)
				return

			} else {
				if ans, err := model.GetAnswer(id); err == nil {

					ans.Hotdown = ans.Hotdown + 1
					ans.Views = ans.Views + 1
					ans.Hotscore = helper.Qhot_QScore(ans.Hotup, ans.Hotdown)
					ans.Hotvote = helper.Qhot_Vote(ans.Hotup, ans.Hotdown)
					ans.Hotness = helper.Qhot(ans.Views, ans.ReplyCount, ans.Hotscore, ans.Views, ans.Created, ans.ReplyTime)

					if _, err := model.PutAnswer(id, ans); err != nil {
						fmt.Println("PutAnswer执行错误:", err)
					} else {
						model.SetAnswerMark(uid, id)
					}
					self.Ctx.WriteString(strconv.Itoa(int(ans.Hotscore)))
				} else {
					return
				}
			}
		} else if name == "topic" {

			if tp, err := model.GetTopic(id); err == nil {

				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)
				//&spades; 没用 ({{.article.Hotdown}})
				self.Ctx.WriteString(strconv.Itoa(int(tp.Hotdown)))
			} else {
				return
			}
		} else if name == "node" {

			if nd, err := model.GetNode(id); err == nil {

				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 {
				return
			}
		} else {
			self.Ctx.Output.SetStatus(304)
		}

	} else {
		self.Ctx.Output.SetStatus(401)
	}

}