mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
feat: add message pass to 400 html template
This commit is contained in:
parent
79207ce24a
commit
b6428b033c
@ -105,8 +105,10 @@ func CreateThread(c *gin.Context) {
|
|||||||
captchaString := form.Value["captcha"][0]
|
captchaString := form.Value["captcha"][0]
|
||||||
isCaptchaValid := captcha.VerifyString(captchaID, captchaString)
|
isCaptchaValid := captcha.VerifyString(captchaID, captchaString)
|
||||||
if !isCaptchaValid {
|
if !isCaptchaValid {
|
||||||
log.Println("error:", err)
|
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||||
c.HTML(http.StatusInternalServerError, "400.html", nil)
|
Message: Repositories.InvalidCaptchaErrorMessage,
|
||||||
|
}
|
||||||
|
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +117,10 @@ func CreateThread(c *gin.Context) {
|
|||||||
title := form.Value["title"][0]
|
title := form.Value["title"][0]
|
||||||
isPostValid := Utils.ValidatePost(title, text)
|
isPostValid := Utils.ValidatePost(title, text)
|
||||||
if !isPostValid {
|
if !isPostValid {
|
||||||
c.HTML(http.StatusBadRequest, "400.html", nil)
|
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||||
|
Message: Repositories.InvalidTitleOrTextErrorMessage,
|
||||||
|
}
|
||||||
|
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,17 +230,21 @@ func UpdateThread(c *gin.Context) {
|
|||||||
captchaString := form.Value["captcha"][0]
|
captchaString := form.Value["captcha"][0]
|
||||||
isCaptchaValid := captcha.VerifyString(captchaID, captchaString)
|
isCaptchaValid := captcha.VerifyString(captchaID, captchaString)
|
||||||
if !isCaptchaValid {
|
if !isCaptchaValid {
|
||||||
log.Println("error:", err)
|
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||||
c.HTML(http.StatusInternalServerError, "400.html", nil)
|
Message: Repositories.InvalidCaptchaErrorMessage,
|
||||||
|
}
|
||||||
|
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: dat shit crashes if no fields in request
|
// TODO: dat shit crashes if no fields in request
|
||||||
text := form.Value["text"][0]
|
text := form.Value["text"][0]
|
||||||
// title := form.Value["title"][0]
|
|
||||||
isPostValid := Utils.ValidatePost("", text)
|
isPostValid := Utils.ValidatePost("", text)
|
||||||
if !isPostValid {
|
if !isPostValid {
|
||||||
c.HTML(http.StatusBadRequest, "400.html", nil)
|
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||||
|
Message: Repositories.InvalidTitleOrTextErrorMessage,
|
||||||
|
}
|
||||||
|
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,19 +32,30 @@ type File struct {
|
|||||||
// HTML Templates Structs
|
// HTML Templates Structs
|
||||||
// HTML Templates Structs
|
// HTML Templates Structs
|
||||||
|
|
||||||
|
// post-form.html
|
||||||
type HtmlFormData struct {
|
type HtmlFormData struct {
|
||||||
FirstPostID int
|
FirstPostID int
|
||||||
CaptchaID string
|
CaptchaID string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// thread.html
|
||||||
type GetThreadHtmlData struct {
|
type GetThreadHtmlData struct {
|
||||||
Thread []Post
|
Thread []Post
|
||||||
FormData HtmlFormData
|
FormData HtmlFormData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// index.html
|
||||||
type GetThreadsHtmlData struct {
|
type GetThreadsHtmlData struct {
|
||||||
Threads []Post
|
Threads []Post
|
||||||
PagesCount int
|
PagesCount int
|
||||||
Page int
|
Page int
|
||||||
FormData HtmlFormData
|
FormData HtmlFormData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 400.html
|
||||||
|
type BadRequestHtmlData struct {
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
var InvalidTitleOrTextErrorMessage = "TITLE OR TEXT SHOULD NOT BE EMPTY"
|
||||||
|
var InvalidCaptchaErrorMessage = "INVALID CAPTCHA"
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="h-100 d-flex justify-content-center align-items-center flex-column">
|
<div class="h-100 d-flex justify-content-center align-items-center flex-column">
|
||||||
<h1>400</h1>
|
<h1>400</h1>
|
||||||
<h1>TITLE OR TEXT SHOULD NOT BE EMPTY</h1>
|
<h1>{{ .Message }}</h1>
|
||||||
<a href="/" class="error-image-link">
|
<a href="/" class="error-image-link">
|
||||||
<img
|
<img
|
||||||
class="error-image"
|
class="error-image"
|
||||||
|
Loading…
Reference in New Issue
Block a user