mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
update templates, structs and controllers to support captcha
This commit is contained in:
parent
e0d44aa0b6
commit
77096ef867
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
<h1 class="display-1 text-center">Welcome to Micrach</h1>
|
||||
|
||||
<div class="container">
|
||||
{{ template "post-form" }}
|
||||
{{ template "post-form" .FormData }}
|
||||
|
||||
<div id="" class="row row-cols-auto gy-4 mb-4">
|
||||
{{ range $Post := .Threads }}
|
||||
|
@ -65,15 +65,20 @@
|
||||
|
||||
{{ define "post-form" }}
|
||||
<div class="col col-12">
|
||||
<form id="postForm" action="/{{ . }}" method="POST" enctype="multipart/form-data">
|
||||
{{ if eq . nil }}
|
||||
{{ if eq .FirstPostID 0 }}
|
||||
<form id="postForm" action="/" method="POST" enctype="multipart/form-data">
|
||||
{{ else }}
|
||||
<form id="postForm" action="/{{ .FirstPostID }}" method="POST" enctype="multipart/form-data">
|
||||
{{ end }}
|
||||
|
||||
{{ if eq .FirstPostID 0 }}
|
||||
<input class="form-control" id="postTitle" placeholder="Title" name="title">
|
||||
{{ end }}
|
||||
<textarea class="form-control" id="postText" rows="5" placeholder="Text" name="text"></textarea>
|
||||
<input class="form-control" type="file" id="postFiles" multiple name="files">
|
||||
|
||||
<div class="row">
|
||||
{{ if ne . nil }}
|
||||
{{ if ne .FirstPostID 0 }}
|
||||
<div class="col">
|
||||
<input class="form-check-input" type="checkbox" value="" id="postSage" name="sage">
|
||||
<label class="form-check-label" for="postSage">
|
||||
@ -84,7 +89,7 @@
|
||||
|
||||
<div class="col text-end">
|
||||
<button class="col btn btn-outline-primary" type="submit" >
|
||||
{{ if ne . nil }}
|
||||
{{ if ne .FirstPostID 0 }}
|
||||
Send
|
||||
{{ else }}
|
||||
Create thread
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{ $FirstPost:= index . 0 }}
|
||||
{{ $FirstPost:= index .Thread 0 }}
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -20,10 +20,10 @@
|
||||
</h1>
|
||||
|
||||
<div class="container">
|
||||
{{ template "post-form" $FirstPost.ID }}
|
||||
{{ template "post-form" .FormData }}
|
||||
|
||||
<div id="postsСontainer">
|
||||
{{range $Post := .}}
|
||||
{{ range $Post := .Thread }}
|
||||
<div class="post-container mb-4">
|
||||
|
||||
{{ $filesLength := len $Post.Files }}
|
||||
|
Loading…
Reference in New Issue
Block a user