예제 #1
0
func (c *MainController) Get() {
	c.Data["IsHome"] = true
	c.Data["IsLogin"] = checkAccount(c.Ctx)
	var err error
	c.Data["Topics"], err = models.GetAllTopic()
	if err != nil {
		beego.Error(nil)
	}
	c.TplNames = "index.html"
}
예제 #2
0
파일: topic.go 프로젝트: wbcz/beeblog
//文章列表
func (this *TopicController) Get() {
	this.TplNames = "topic.html"
	this.Data["IsTopic"] = true
	this.Data["IsLogin"] = checkAccount(this.Ctx)

	var err error
	this.Data["Topics"], err = models.GetAllTopic("", "", false)
	if err != nil {
		beego.Error(err)
	}
}
예제 #3
0
파일: topic.go 프로젝트: CQ-Wangrz/beeblog
func (this *TopicController) Get() {
	this.Data["IsLogin"] = checkAccount(this.Ctx)
	this.Data["IsTopic"] = true
	this.TplName = "topic.html"
	topics, err := models.GetAllTopic(false)
	if err != nil {
		beego.Error(err)
	} else {
		this.Data["Topics"] = topics
	}
}
예제 #4
0
func (this *MainController) Get() {
	this.Data["IsHome"] = true
	this.TplName = "home.html"
	fmt.Println(this.Data["IsLogin"])
	this.Data["IsLogin"] = checkAccount(this.Ctx)

	topics, err := models.GetAllTopic(true)
	if err != nil {
		beego.Error(err)
	} else {
		this.Data["Topics"] = topics
	}

	fmt.Println(this.Data["IsLogin"])
}
예제 #5
0
파일: home.go 프로젝트: wbcz/beeblog
func (this *MainController) Get() {
	this.Data["IsHome"] = true
	this.TplNames = "home.html"

	this.Data["IsLogin"] = checkAccount(this.Ctx)
	var err error
	this.Data["Topics"], err = models.GetAllTopic(this.Input().Get("cate"), this.Input().Get("label"), true)
	if err != nil {
		beego.Error(err)
	}

	categories, err := models.GetAllCategory()
	if err != nil {
		beego.Error(err)
	}
	this.Data["Categories"] = categories

}
예제 #6
0
파일: topic.go 프로젝트: moonstudio/MyTools
func (t *TopicController) Post() {
	if !checkAccount(t.Ctx) {
		t.TplNames = "login.html"
		return
	}
	op := t.Input().Get("op")
	switch op {
	case "add":
		title := t.Input().Get("title")
		content := t.Input().Get("content")
		category := t.Input().Get("category")
		_, fh, ferr := t.GetFile("attachment")
		if ferr != nil {
			beego.Error(ferr)
		}
		var attachment string
		if fh != nil {
			attachment = fh.Filename
			beego.Info(attachment)
			ferr = t.SaveToFile("attachment", path.Join("attachment", attachment))
			if ferr != nil {
				beego.Error(ferr)
			}
		}
		err := models.AddTopic(title, content, category, attachment)
		if err != nil {
			beego.Error(err)
		}
		t.Redirect("/topic", 301)
		return
	case "edit":
		return
	case "editsubmit":
		id := t.Input().Get("id")
		title := t.Input().Get("title")
		content := t.Input().Get("content")
		category := t.Input().Get("category")
		_, fh, ferr := t.GetFile("attachment")
		if ferr != nil {
			beego.Error(ferr)
		}
		var attachment string
		if fh != nil {
			attachment = fh.Filename
			fmt.Println("#############################################", attachment)
			beego.Info(attachment)
			ferr = t.SaveToFile("attachment", path.Join("attachment", attachment))
			if ferr != nil {
				beego.Error(ferr)
			}
		}
		err := models.UpdateTopic(id, title, content, category, attachment)
		if err != nil {
			beego.Error(err)
		}
		t.Redirect("/topic", 301)
		return
	default:
		t.Data["IsTopic"] = true
		t.TplNames = "topic.html"
		var err error
		t.Data["Topics"], err = models.GetAllTopic()
		if err != nil {
			beego.Error(nil)
		}
	}
}
예제 #7
0
파일: topic.go 프로젝트: moonstudio/MyTools
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)
		}
	}

}