mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
feat: add simple post validation
This commit is contained in:
parent
e5bbc585e3
commit
f24c97f5e0
@ -86,9 +86,14 @@ func CreateThread(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TODO: dat shit crashes if no fields in request
|
||||
// TODO: add validation (title or text)
|
||||
text := form.Value["text"][0]
|
||||
title := form.Value["title"][0]
|
||||
isPostValid := Utils.ValidatePost(title, text)
|
||||
if !isPostValid {
|
||||
c.HTML(http.StatusBadRequest, "400.html", nil)
|
||||
return
|
||||
}
|
||||
|
||||
filesInRequest := form.File["files"]
|
||||
|
||||
conn, err := Db.Pool.Acquire(context.TODO())
|
||||
@ -177,9 +182,14 @@ func UpdateThread(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TODO: dat shit crashes if no fields in request
|
||||
// TODO: add validation (title or text)
|
||||
text := form.Value["text"][0]
|
||||
title := form.Value["title"][0]
|
||||
isPostValid := Utils.ValidatePost(title, text)
|
||||
if !isPostValid {
|
||||
c.HTML(http.StatusBadRequest, "400.html", nil)
|
||||
return
|
||||
}
|
||||
|
||||
filesInRequest := form.File["files"]
|
||||
isSageField := form.Value["sage"]
|
||||
var isSageString string
|
||||
|
26
templates/400.html
Normal file
26
templates/400.html
Normal file
@ -0,0 +1,26 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
{{ template "static" }}
|
||||
<link
|
||||
href="/static/error-image.css"
|
||||
rel="stylesheet"
|
||||
>
|
||||
|
||||
{{ template "static-meta" }}
|
||||
</head>
|
||||
|
||||
<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>
|
||||
<a href="/" class="error-image-link">
|
||||
<img
|
||||
class="error-image"
|
||||
src="/static/images/errors/404.png"
|
||||
alt="Bad request"
|
||||
>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -46,3 +46,7 @@ func CreateThreadFolder(postID int) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidatePost(title, text string) bool {
|
||||
return (title == "" && text != "") || (title != "" && text == "")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user