Esempio n. 1
0
//UserNew handles GET /admin/new_user route
func UserNew(c *gin.Context) {
	h := helpers.DefaultH(c)
	h["Title"] = "New user"
	h["Active"] = "users"
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()
	c.HTML(http.StatusOK, "users/form", h)
}
Esempio n. 2
0
//SignUpGet handles GET /signup route
func SignUpGet(c *gin.Context) {
	h := helpers.DefaultH(c)
	h["Title"] = "Basic GIN web-site signup form"
	h["Active"] = "signup"
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()
	c.HTML(http.StatusOK, "auth/signup", h)
}
Esempio n. 3
0
//PostNew handles GET /admin/new_post route
func PostNew(c *gin.Context) {
	tags, _ := models.GetTags()
	h := helpers.DefaultH(c)
	h["Title"] = "New post entry"
	h["Active"] = "posts"
	h["Tags"] = tags
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()

	c.HTML(http.StatusOK, "posts/form", h)
}
Esempio n. 4
0
//PageGet handles GET /pages/:id route
func PageGet(c *gin.Context) {
	page, err := models.GetPage(c.Param("id"))
	if err != nil || !page.Published {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = page.Name
	h["Description"] = template.HTML(string(blackfriday.MarkdownCommon([]byte(page.Description))))
	h["Active"] = "pages"
	c.HTML(http.StatusOK, "pages/show", h)
}
Esempio n. 5
0
//TagIndex handles GET /admin/tags route
func TagIndex(c *gin.Context) {
	list, err := models.GetTags()
	if err != nil {
		c.HTML(http.StatusInternalServerError, "errors/500", nil)
		logrus.Error(err)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = "List of tags"
	h["List"] = list
	h["Active"] = "tags"
	c.HTML(http.StatusOK, "tags/index", h)
}
Esempio n. 6
0
//PostGet handles GET /posts/:id route
func PostGet(c *gin.Context) {
	post, err := models.GetPost(c.Param("id"))
	if err != nil || !post.Published {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = post.Name
	h["Description"] = template.HTML(string(blackfriday.MarkdownCommon([]byte(post.Description))))
	h["Post"] = post
	h["Active"] = fmt.Sprintf("posts/%d", post.ID)
	c.HTML(http.StatusOK, "posts/show", h)
}
Esempio n. 7
0
//ArchiveGet handles GET /archives/:year/:month route
func ArchiveGet(c *gin.Context) {
	year, _ := strconv.Atoi(c.Param("year"))
	month, _ := strconv.Atoi(c.Param("month"))
	list, err := models.GetPostsByArchive(year, month)
	if err != nil {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = fmt.Sprintf("%s %d archives", time.Month(month).String(), year)
	h["List"] = list
	h["Active"] = fmt.Sprintf("archives/%d/%02d", year, month)
	c.HTML(http.StatusOK, "archives/show", h)
}
Esempio n. 8
0
//UserEdit handles GET /admin/users/:id/edit route
func UserEdit(c *gin.Context) {
	user, _ := models.GetUser(c.Param("id"))
	if user.ID == 0 {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = "Edit user"
	h["Active"] = "users"
	h["User"] = user
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()
	c.HTML(http.StatusOK, "users/form", h)
}
Esempio n. 9
0
//PageEdit handles GET /admin/pages/:id/edit route
func PageEdit(c *gin.Context) {
	page, _ := models.GetPage(c.Param("id"))
	if page.ID == 0 {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = "Edit page"
	h["Active"] = "pages"
	h["Page"] = page
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()
	c.HTML(http.StatusOK, "pages/form", h)
}
Esempio n. 10
0
//PostEdit handles GET /admin/posts/:id/edit route
func PostEdit(c *gin.Context) {
	post, _ := models.GetPost(c.Param("id"))
	if post.ID == 0 {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	tags, _ := models.GetTags()
	h := helpers.DefaultH(c)
	h["Title"] = "Edit post entry"
	h["Active"] = "posts"
	h["Post"] = post
	h["Tags"] = tags
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()
	c.HTML(http.StatusOK, "posts/form", h)
}
Esempio n. 11
0
//TagGet handles GET /tags/:name route
func TagGet(c *gin.Context) {
	tag, err := models.GetTag(c.Param("name"))
	if err != nil {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	list, err := models.GetPostsByTag(tag.Name)
	if err != nil {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}

	h := helpers.DefaultH(c)
	h["Title"] = tag.Name
	h["Active"] = "tags"
	h["List"] = list
	c.HTML(http.StatusOK, "tags/show", h)
}
Esempio n. 12
0
//HomeGet handles GET / route
func HomeGet(c *gin.Context) {
	h := helpers.DefaultH(c)
	h["Title"] = "Welcome to basic GIN blog"
	h["Active"] = "home"
	c.HTML(http.StatusOK, "home/show", h)
}
Esempio n. 13
0
//AdminGet handles GET /admin/ route
func AdminGet(c *gin.Context) {
	h := helpers.DefaultH(c)
	h["Title"] = "Admin dashboard"
	c.HTML(http.StatusOK, "dashboard/show", h)
}