Exemple #1
0
func (c *TopicController) Get() {
	c.Data["IsTopic"] = true
	c.Data["IsLogin"] = checkAccount(c.Ctx)

	op := c.Input().Get("op")
	switch op {
	case "del":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}

		err := models.DelTopic(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/topic", 302)
	}

	var err error
	c.Data["Topics"], err = models.GetAllTopic("", false)

	if err != nil {
		beego.Error(err)
	}

	c.TplNames = "topic.html"
}
Exemple #2
0
func (this *TopicController) Delete() {
	if !checkAccount(this.Ctx) {
		this.Redirect("/login", 302)
		return
	}

	tId := this.Input().Get("tid")
	if "0" != tId {
		models.DelTopic(tId)
	}
	this.Redirect("/topic", 302)
	return
}
Exemple #3
0
func (this *TopicController) Post() {
	if !checkAccount(this.Ctx) {
		this.Redirect("/login", 302)
		return
	}
	tid := this.Input().Get("tid")
	title := this.Input().Get("title")
	content := this.Input().Get("content")
	label := this.Input().Get("label")
	category := this.Input().Get("category")

	if len(tid) != 0 {
		var err error
		beego.Debug("modify", title, content, label, category)
		err = models.ModifyTopic(tid, title, category, label, content)
		if err != nil {
			beego.Debug(err)
			this.Redirect("/topic", 302)
			return
		}
		this.Redirect("/topic", 302)

	} else {
		op := this.Input().Get("op")
		switch op {
		case "add":
			title := this.Input().Get("title")
			content := this.Input().Get("content")
			category := this.Input().Get("category")
			var err error
			err = models.AddTopic(title, category, label, content)
			if err != nil {
				return
			}
			this.Redirect("/topic", 302)
		case "del":
			id := this.Input().Get("id")
			if len(id) == 0 {
				break
			}

			err := models.DelTopic(id)
			if err != nil {
				beego.Error(err)
			}
			this.Redirect("/topic", 302)
		}
	}

}