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]
|
||||
isCaptchaValid := captcha.VerifyString(captchaID, captchaString)
|
||||
if !isCaptchaValid {
|
||||
log.Println("error:", err)
|
||||
c.HTML(http.StatusInternalServerError, "400.html", nil)
|
||||
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||
Message: Repositories.InvalidCaptchaErrorMessage,
|
||||
}
|
||||
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||
return
|
||||
}
|
||||
|
||||
@ -115,7 +117,10 @@ func CreateThread(c *gin.Context) {
|
||||
title := form.Value["title"][0]
|
||||
isPostValid := Utils.ValidatePost(title, text)
|
||||
if !isPostValid {
|
||||
c.HTML(http.StatusBadRequest, "400.html", nil)
|
||||
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||
Message: Repositories.InvalidTitleOrTextErrorMessage,
|
||||
}
|
||||
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||
return
|
||||
}
|
||||
|
||||
@ -225,17 +230,21 @@ func UpdateThread(c *gin.Context) {
|
||||
captchaString := form.Value["captcha"][0]
|
||||
isCaptchaValid := captcha.VerifyString(captchaID, captchaString)
|
||||
if !isCaptchaValid {
|
||||
log.Println("error:", err)
|
||||
c.HTML(http.StatusInternalServerError, "400.html", nil)
|
||||
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||
Message: Repositories.InvalidCaptchaErrorMessage,
|
||||
}
|
||||
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: dat shit crashes if no fields in request
|
||||
text := form.Value["text"][0]
|
||||
// title := form.Value["title"][0]
|
||||
isPostValid := Utils.ValidatePost("", text)
|
||||
if !isPostValid {
|
||||
c.HTML(http.StatusBadRequest, "400.html", nil)
|
||||
errorHtmlData := Repositories.BadRequestHtmlData{
|
||||
Message: Repositories.InvalidTitleOrTextErrorMessage,
|
||||
}
|
||||
c.HTML(http.StatusInternalServerError, "400.html", errorHtmlData)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -32,19 +32,30 @@ type File struct {
|
||||
// HTML Templates Structs
|
||||
// HTML Templates Structs
|
||||
|
||||
// post-form.html
|
||||
type HtmlFormData struct {
|
||||
FirstPostID int
|
||||
CaptchaID string
|
||||
}
|
||||
|
||||
// thread.html
|
||||
type GetThreadHtmlData struct {
|
||||
Thread []Post
|
||||
FormData HtmlFormData
|
||||
}
|
||||
|
||||
// index.html
|
||||
type GetThreadsHtmlData struct {
|
||||
Threads []Post
|
||||
PagesCount int
|
||||
Page int
|
||||
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>
|
||||
<div class="h-100 d-flex justify-content-center align-items-center flex-column">
|
||||
<h1>400</h1>
|
||||
<h1>TITLE OR TEXT SHOULD NOT BE EMPTY</h1>
|
||||
<h1>{{ .Message }}</h1>
|
||||
<a href="/" class="error-image-link">
|
||||
<img
|
||||
class="error-image"
|
||||
|
Loading…
Reference in New Issue
Block a user