Beispiel #1
0
func (this *TopicController) Post() {
	if !CheckAccount(this.Ctx) {
		this.Redirect("/login", 302)
		return
	}

	var err error
	title := this.Input().Get("tname")
	content := this.Input().Get("tcontent")
	category := this.Input().Get("category")
	id := this.Input().Get("id")
	if len(id) != 0 {
		err = models.ModifyTopic(id, title, category, content)
		if err != nil {
			beego.Error(err)
		}
	} else {
		err = models.AddTopic(title, category, content)
		if err != nil {
			beego.Error(err)
		}
	}

	this.Redirect("/topic", 302)
}
Beispiel #2
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")
	category := this.Input().Get("category")
	lable := this.Input().Get("lable")

	var err error
	if len(tid) == 0 {
		err = models.AddTopic(title, category, lable, content)
	} else {
		err = models.ModifyTopic(tid, title, category, lable, content)
	}

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

	this.Redirect("/topic", 302)
}
Beispiel #3
0
func (this *TopicController) Post() {
	if !checkCookie(this.Ctx) {
		this.Redirect("/login", 302)
		return
	}
	this.Data["isLogin"] = "******"
	topicName := this.Input().Get("topicName")
	topicContent := this.Input().Get("topicContent")
	topicId := this.Input().Get("topicId")
	category := this.Input().Get("category")
	labels := this.Input().Get("labels")

	var err error
	if len(topicId) == 0 {
		if len(category) != 0 {
			err = models.AddTopic(topicName, labels, category, topicContent)
		} else {
			this.Redirect("/category", 302)
			return
		}
	} else {
		err = models.ModifyTopic(topicId, topicName, labels, category, topicContent)
	}

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

	this.Redirect("/topic", 301)
	return
}
Beispiel #4
0
func (this *AdminTopicController) Post() {

	op := this.Input().Get("op")

	switch op {

	case "add":

		title := this.Input().Get("title")
		content := this.Input().Get("content")
		category := this.Input().Get("category")

		if len(title) == 0 {
			break
		}

		if len(content) == 0 {
			break
		}

		if len(category) == 0 {
			break
		}

		err := models.AddTopic(title, content, category)

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

		this.Redirect("./admintopic", 301)
		return

	case "save":

		id := this.Input().Get("id")
		if len(id) == 0 {
			this.Redirect("./admintopic", 301)
			return
		}

		title := this.Input().Get("title")
		content := this.Input().Get("content")
		category := this.Input().Get("category")

		err := models.UpdateTopic(id, title, content, category)

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

		this.Redirect("./admintopic", 301)
		return
	}
}