guestbook qol improvements
This commit is contained in:
parent
5080c566ac
commit
2c6b124664
|
@ -27,8 +27,8 @@ func validateGuestbookEntry(entry *database.GuestbookEntry) []string {
|
|||
}
|
||||
|
||||
messageLength := len(entry.Message)
|
||||
if messageLength < 10 || messageLength > 500 {
|
||||
errors = append(errors, "message must be between 10 and 500 characters")
|
||||
if messageLength > 500 {
|
||||
errors = append(errors, "message cannot be longer than 500 characters")
|
||||
}
|
||||
|
||||
newLines := strings.Count(entry.Message, "\n")
|
||||
|
@ -58,19 +58,17 @@ func SignGuestbookContinuation(context *RequestContext, req *http.Request, resp
|
|||
Name: name,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
formErrors.Errors = append(formErrors.Errors, validateGuestbookEntry(entry)...)
|
||||
|
||||
if len(formErrors.Errors) > 0 {
|
||||
(*context.TemplateData)["FormError"] = formErrors
|
||||
return failure(context, req, resp)
|
||||
}
|
||||
|
||||
err := verifyHCaptcha(context.Args.HcaptchaSecret, hCaptchaResponse)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
resp.WriteHeader(http.StatusBadRequest)
|
||||
formErrors.Errors = append(formErrors.Errors, "hCaptcha verification failed")
|
||||
}
|
||||
if len(formErrors.Errors) > 0 {
|
||||
(*context.TemplateData)["FormError"] = formErrors
|
||||
(*context.TemplateData)["EntryForm"] = entry
|
||||
return failure(context, req, resp)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
{{ if not .EntryForm }}
|
||||
placeholder="hoi!"
|
||||
{{ end }}
|
||||
>{{ if .EntryForm }}{{ .EntryForm.Message }}{{ end }}
|
||||
</textarea>
|
||||
|
||||
>{{ if .EntryForm }}{{ .EntryForm.Message }}{{ end }}</textarea>
|
||||
<div
|
||||
class="h-captcha"
|
||||
data-sitekey="{{ .HcaptchaArgs.SiteKey }}"
|
||||
|
|
Loading…
Reference in New Issue