// 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) } }
// 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) }
func license(w http.ResponseWriter, req *http.Request) { lib.Render(w, "application/license", lib.DefaultViewData()) }