Ejemplo n.º 1
0
//管理员后台后台认证
func (self *RootController) Prepare() {
	self.BaseController.Prepare()

	if !utils.IsSpider(self.Ctx.Request.UserAgent()) {
		if self.Data["userrole"] != -1000 {
			self.Redirect("/u/signin/", 302)
		} else {
			self.Data["remoteproto"] = self.Ctx.Request.Proto
			self.Data["remotehost"] = self.Ctx.Request.Host
			self.Data["remoteos"] = runtime.GOOS
			self.Data["remotearch"] = runtime.GOARCH
			self.Data["remotecpus"] = runtime.NumCPU()
			self.Data["golangver"] = runtime.Version()
		}
	} else {
		self.Redirect("/", 302)
	}
}
Ejemplo n.º 2
0
func (self *LikeOrHateController) Get() {
	if utils.IsSpider(self.Ctx.Request.UserAgent()) == true {
		self.Ctx.Output.SetStatus(401)
		return
	}

	name := self.GetString(":name")
	id, _ := self.GetInt64(":id")
	uid, _ := self.GetSession("userid").(int64)

	if models.IsAnswerMark(uid, id) {
		self.Ctx.Output.SetStatus(304)
		return
	} else {
		ans := &models.Reply{Id: id}
		if err := ans.ReadOneOnly("Views", "ReplyCount", "Created", "ReplyTime", "Hotup", "Hotdown", "Hotscore", "Hotvote", "Hotness"); err == orm.ErrNoRows {
			return
		}

		if name == "hate" {
			ans.Hotdown = ans.Hotdown + 1
		} else if name == "like" {
			ans.Hotup = ans.Hotup + 1
		}

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

		if _, err := ans.Update("Hotup", "Hotdown", "Hotscore", "Hotvote", "Hotness"); err != nil {
			fmt.Println("PutQuestion执行错误:", err)
		} else {
			models.SetAnswerMark(uid, id)
		}

		self.Ctx.WriteString(strconv.Itoa(int(ans.Hotscore)))
	}
}