Example #1
0
func (this *HomeController) Get() {
	this.Data["IsHome"] = true
	this.TplNames = "home.html"

	this.Data["IsLogin"] = checkAccount(this.Ctx)

	category := this.Input().Get("cate")

	var err error
	topics := make([]*models.Topic, 0)

	if len(category) == 0 {
		topics, err = models.GetAllTopics(true)
	} else {
		topics, err = models.GetTopicsByCategory(category, true)
	}
	if err != nil {
		beego.Error(err)
	}
	this.Data["Topics"] = topics

	Category, err := models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}

	this.Data["Categories"] = Category

}
Example #2
0
func (c *CategoryController) Get() {
	op := c.Input().Get("op")
	switch op {
	case "add":
		category := c.Input().Get("category")
		if len(category) == 0 {
			break
		}
		err := models.AddCategory(category)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 301)
		return

	case "del":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.DelCategory(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 301)
	}

	c.Data["IsCategory"] = true
	c.TplNames = "category.html"
	var err error
	c.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Example #3
0
func (t *TopicController) Add() {
	if !checkAccount(t.Ctx) {
		t.TplNames = "login.html"
		return
	}
	t.Data["IsLogin"] = checkAccount(t.Ctx)
	t.Data["IsTopic"] = true
	t.Data["Category"], _ = models.GetAllCategories()
	t.Data["Sheng"], _ = models.GetXzqById("")
	t.TplNames = "topic_add.html"
}
Example #4
0
func (this *CategoryController) Get() {
	op := this.Input().Get("op")

	switch op {
	case "add":
		name := this.Input().Get("name")
		if len(name) == 0 {
			break
		}
		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}
		this.Redirect("/category", 301)
		return
	case "del":
		println("ssssssss....................")

		id := this.Input().Get("id")
		if len(id) == 0 {
			break
		}

		println(".......category 1")

		err := models.DelCategory(id)

		println(".......category 2")

		if err != nil {
			beego.Error(err)
		}
		println(".......category 3")
		this.Redirect("/category", 301)
		return
	}

	this.TplNames = "category.html"
	this.Data["IsCategory"] = true

	var err error
	this.Data["Categories"], err = models.GetAllCategories()

	if err != nil {
		beego.Error(err)
	}
}
Example #5
0
func (this *CategoryController) Get() {
	this.Data["IsCategory"] = true

	this.Data["IsLogin"] = checkAccount(this.Ctx)
	this.TplNames = "category.html"

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

	switch op {
	case "add":
		name := this.Input().Get("category")
		beego.Debug(name)
		if len(name) == 0 {
			break
		}
		/* 需要在models 里面处理 */
		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}
		this.Redirect("/category", 302)
		return

	case "del":
		id := this.Input().Get("id")
		beego.Debug(id)
		if len(id) == 0 {
			break
		}

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

	/* 取值分类中的所以列 Categories 在页面中*/
	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Example #6
0
func (this *HomeController) Get() {
	this.Data["IsHome"] = true
	this.TplNames = "home.html"
	this.Data["IsLogin"] = checkAccount(this.Ctx)

	topics, err := models.GetAllTopics(this.Input().Get("cate"), true)
	if err != nil {
		beego.Error(err)
	}
	this.Data["Topics"] = topics

	categories, err := models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
	this.Data["Categories"] = categories
}
Example #7
0
func (this *CategoryController) Get() {
	this.Data["IsCategory"] = true
	this.Data["IsLogin"] = checkAccount(this.Ctx)

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

	switch op {
	case "add":
		name := this.Input().Get("name")

		if len(name) == 0 {
			break
		}

		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}

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

		err := models.DelCategory(id)

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

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

	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	this.TplName = "category.html"

	if err != nil {
		beego.Error(err)
	}
}
Example #8
0
func (c *MainController) Get() {
	c.TplNames = "home.html"
	c.Data["IsHome"] = true
	c.Data["IsLogin"] = checkAccount(c.Ctx)

	topics, err := models.GetAllTopics(c.Input().Get("cate"), c.Input().Get("label"), true)
	if err != nil {
		beego.Error(err.Error())
	} else {
		c.Data["Topics"] = topics
	}

	categories, err := models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}

	c.Data["Categories"] = categories
}
Example #9
0
func (this *CategoryController) Get() {
	op := this.Input().Get("op")
	name := this.Input().Get("name")
	fmt.Println("op value:" + op + " name value:" + name)
	switch op {
	case "add":
		fmt.Println("categoryADD")
		name := this.Input().Get("name")
		if len(name) == 0 {
			break
		}
		err := models.AddCategory(name)
		if err != nil {
			beego.Error(err)
		}
		this.Redirect("/category", 301)
		return
	case "del":
		fmt.Println("categoryDEL")
		id := this.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.DelCategories(id)
		if err != nil {
			beego.Error(err)
		}
		this.Redirect("/category", 301)
		return
	}
	this.Data["IsCategory"] = true
	this.TplName = "category.html"

	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Example #10
0
func (c *MainController) Get() {
	c.Data["Website"] = "beego.me"
	c.Data["Email"] = "*****@*****.**"
	c.Data["IsHome"] = true
	c.Data["IsLogin"] = checkAccount(c.Ctx)

	topics, err := models.GetAllTopics(c.Input().Get("cate"), true)
	if err != nil {
		beego.Error(err)
	} else {
		c.Data["Topics"] = topics
	}

	c.TplName = "home.html"

	categories, err := models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}

	c.Data["Categories"] = categories
}
Example #11
0
func (c *CategroyController) Get() {

	op := c.Input().Get("op")
	switch op {
	case "add":
		cname := c.Input().Get("cname")
		if len(cname) == 0 {
			break
		}
		err := models.AddCategory(cname)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 301)
		return
	case "del":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.DelCategory(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/category", 301)
		return
	default:
		c.Data["IsLogin"] = checkAccount(c.Ctx)
		c.Data["IsCategray"] = true
		c.TplNames = "categroy.html"
		var err error
		c.Data["Categories"], err = models.GetAllCategories()
		if err != nil {
			beego.Error(nil)
		}
	}

}
Example #12
0
func (t *TopicController) Get() {

	op := t.Input().Get("op")
	switch op {
	case "add":

		return
	case "edit":
		if !checkAccount(t.Ctx) {
			t.TplNames = "login.html"
			return
		}
		id := t.Input().Get("id")

		topic, err := models.GetTopicById(id)
		t.Data["Topic"] = topic
		t.Data["Category"], _ = models.GetAllCategories()
		t.Data["IsLogin"] = checkAccount(t.Ctx)
		t.TplNames = "topic_edit.html"
		if err != nil {
			beego.Error(err)
		}
		return
	case "info":
		id := t.Input().Get("id")

		topic, err := models.GetTopicById(id)
		t.Data["Topic"] = topic
		t.Data["Category"], _ = models.GetAllCategories()
		t.Data["Comment"], _ = models.GetCommentById(id)
		t.Data["IsLogin"] = checkAccount(t.Ctx)
		t.TplNames = "topic_info.html"
		if err != nil {
			beego.Error(err)
		}
		return
	case "del":
		if !checkAccount(t.Ctx) {
			t.TplNames = "login.html"
			return
		}
		id := t.Input().Get("id")
		if len(id) == 0 {
			break
		}
		err := models.DelTopic(id)
		if err != nil {
			beego.Error(err)
		}
		t.Redirect("/topic", 301)
		return

	default:
		t.Data["IsLogin"] = checkAccount(t.Ctx)
		t.Data["IsTopic"] = true
		t.TplNames = "topic.html"
		var err error
		t.Data["Topics"], err = models.GetAllTopic()
		if err != nil {
			beego.Error(nil)
		}
	}

}