// HandleCreateShow serves the create form via GET for stories func HandleCreateShow(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { // When not allowed to post stories, redirect to register screen router.Redirect(context, "/users/create") } // Render the template view := view.New(context) story := stories.New() view.AddKey("story", story) view.AddKey("meta_title", "TechCity News Submit") return view.Render() }
// HandleCreateShow serves the create form via GET for comments func HandleCreateShow(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Render the template view := view.New(context) comment := comments.New() view.AddKey("comment", comment) // TODO: May have to validate parent_id or story_id view.AddKey("story_id", context.ParamInt("story_id")) view.AddKey("parent_id", context.ParamInt("parent_id")) return view.Render() }
// HandleIndex serves a GET request at /users func HandleIndex(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Query for most recent 100 users q := users.Query().Order("points desc, created_at desc").Limit(100) // Fetch 100 of them userList, err := users.FindAll(q) if err != nil { return router.InternalError(err) } // Get a count of all users count, err := q.Count() if err != nil { return router.InternalError(err) } // Get a count of admin users adminsCount, err := q.Where("role=100").Count() if err != nil { return router.InternalError(err) } // Serve template view := view.New(context) view.AddKey("users", userList) view.AddKey("count", count) view.AddKey("adminsCount", adminsCount) return view.Render() }