diff --git a/controllers/threads_controller.go b/controllers/threads_controller.go index db43dcb..ab16f7d 100644 --- a/controllers/threads_controller.go +++ b/controllers/threads_controller.go @@ -51,17 +51,20 @@ func GetThreads(c *gin.Context) { c.HTML(http.StatusNotFound, "404.html", nil) return } - data := Repositories.IndexPageData{ - Threads: threads, - PagesCount: pagesCount, - Page: page, - } csrfToken := csrf.GetToken(c) c.SetCookie("csrf", csrfToken, 60, "/", "", true, true) + captchaID := captcha.New() - log.Println(captchaID) - c.HTML(http.StatusOK, "index.html", data) + htmlData := Repositories.GetThreadsHtmlData{ + Threads: threads, + PagesCount: pagesCount, + Page: page, + FormData: Repositories.HtmlFormData{ + CaptchaID: captchaID, + }, + } + c.HTML(http.StatusOK, "index.html", htmlData) } func GetThread(c *gin.Context) { @@ -84,7 +87,17 @@ func GetThread(c *gin.Context) { csrfToken := csrf.GetToken(c) c.SetCookie("csrf", csrfToken, 60, "/", "", true, true) - c.HTML(http.StatusOK, "thread.html", thread) + + firstPost := thread[0] + captchaID := captcha.New() + htmlData := Repositories.GetThreadHtmlData{ + Thread: thread, + FormData: Repositories.HtmlFormData{ + FirstPostID: firstPost.ID, + CaptchaID: captchaID, + }, + } + c.HTML(http.StatusOK, "thread.html", htmlData) } func CreateThread(c *gin.Context) { diff --git a/repositories/structs.go b/repositories/structs.go index e019585..cbfa837 100644 --- a/repositories/structs.go +++ b/repositories/structs.go @@ -2,6 +2,10 @@ package repositories import "time" +// DB Structs +// DB Structs +// DB Structs + type Post struct { ID int `json:"id"` IsParent bool `json:"-"` @@ -24,8 +28,23 @@ type File struct { Size int `json:"size"` } -type IndexPageData struct { +// HTML Templates Structs +// HTML Templates Structs +// HTML Templates Structs + +type HtmlFormData struct { + FirstPostID int + CaptchaID string +} + +type GetThreadHtmlData struct { + Thread []Post + FormData HtmlFormData +} + +type GetThreadsHtmlData struct { Threads []Post PagesCount int Page int + FormData HtmlFormData } diff --git a/templates/index.html b/templates/index.html index c6fc546..01a2997 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@

Welcome to Micrach

- {{ template "post-form" }} + {{ template "post-form" .FormData }}
{{ range $Post := .Threads }} diff --git a/templates/templates.html b/templates/templates.html index e140627..975b33d 100644 --- a/templates/templates.html +++ b/templates/templates.html @@ -65,15 +65,20 @@ {{ define "post-form" }}
-
- {{ if eq . nil }} + {{ if eq .FirstPostID 0 }} + + {{ else }} + + {{ end }} + + {{ if eq .FirstPostID 0 }} {{ end }}
- {{ if ne . nil }} + {{ if ne .FirstPostID 0 }}