示例#1
0
文件: root.go 项目: mssola/todo
// RootIndex renders the root page. It has three different options:
//
//  1. If there's no user, it renders the "Create user" page.
//  2. If the current user is not logged in, it render the "Login" page.
//  3. If the current user is logged in, then it redirects the user to the
//     /topics page.
func RootIndex(res http.ResponseWriter, req *http.Request) {
	id := lib.GetCookie(req, "userId")

	if id == nil {
		count := Count("users")
		if count == 0 {
			lib.Render(res, "users/new", lib.DefaultViewData())
		} else {
			lib.Render(res, "application/login", lib.DefaultViewData())
		}
	} else {
		http.Redirect(res, req, "/topics", http.StatusFound)
	}
}
示例#2
0
文件: topics.go 项目: mssola/todo
// Sends the main page with the given topic rendered in it as
// the current one.
func renderShow(res http.ResponseWriter, topic *Topic, print bool) {
	var topics []Topic
	_, err := Db.Select(&topics, "select * from topics order by name")
	if err != nil {
		log.Printf("Select went wrong: %v", err)
	}
	topic.RenderMarkdown()

	// And render the page.
	o := &TopicData{
		Current: topic,
		Topics:  topics,
	}
	o.JS = "topics"
	o.Print = print
	o.Prefix = os.Getenv("TODO_ASSET_PREFIX")
	lib.Render(res, "topics/show", o)
}
示例#3
0
文件: routing.go 项目: mssola/todo
func license(w http.ResponseWriter, req *http.Request) {
	lib.Render(w, "application/license", lib.DefaultViewData())
}