summaryrefslogtreecommitdiff
path: root/api/guestbook.go
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth@simponic.xyz>2024-04-03 17:53:50 -0600
committerElizabeth Hunt <elizabeth@simponic.xyz>2024-04-03 17:53:50 -0600
commitf38e8719c2a8537fe9b64ed8ceca45858a58e498 (patch)
tree5cf2c7c7f6396f75bdb841db00638e4eef8e81e8 /api/guestbook.go
parente398cf05402c010d594cea4e2dea307ca1a36dbe (diff)
downloadhatecomputers.club-f38e8719c2a8537fe9b64ed8ceca45858a58e498.tar.gz
hatecomputers.club-f38e8719c2a8537fe9b64ed8ceca45858a58e498.zip
make it compile
Diffstat (limited to 'api/guestbook.go')
-rw-r--r--api/guestbook.go88
1 files changed, 0 insertions, 88 deletions
diff --git a/api/guestbook.go b/api/guestbook.go
deleted file mode 100644
index ee3c79a..0000000
--- a/api/guestbook.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package api
-
-import (
- "log"
- "net/http"
- "strings"
-
- "git.hatecomputers.club/hatecomputers/hatecomputers.club/database"
- "git.hatecomputers.club/hatecomputers/hatecomputers.club/utils"
-)
-
-type HcaptchaArgs struct {
- SiteKey string
-}
-
-func validateGuestbookEntry(entry *database.GuestbookEntry) []string {
- errors := []string{}
-
- if entry.Name == "" {
- errors = append(errors, "name is required")
- }
-
- if entry.Message == "" {
- errors = append(errors, "message is required")
- }
-
- messageLength := len(entry.Message)
- if messageLength > 500 {
- errors = append(errors, "message cannot be longer than 500 characters")
- }
-
- newLines := strings.Count(entry.Message, "\n")
- if newLines > 10 {
- errors = append(errors, "message cannot contain more than 10 new lines")
- }
-
- return errors
-}
-
-func SignGuestbookContinuation(context *RequestContext, req *http.Request, resp http.ResponseWriter) ContinuationChain {
- return func(success Continuation, failure Continuation) ContinuationChain {
- name := req.FormValue("name")
- message := req.FormValue("message")
-
- formErrors := FormError{
- Errors: []string{},
- }
-
- entry := &database.GuestbookEntry{
- ID: utils.RandomId(),
- Name: name,
- Message: message,
- }
- formErrors.Errors = append(formErrors.Errors, validateGuestbookEntry(entry)...)
-
- if len(formErrors.Errors) == 0 {
- _, err := database.SaveGuestbookEntry(context.DBConn, entry)
- if err != nil {
- log.Println(err)
- formErrors.Errors = append(formErrors.Errors, "failed to save entry")
- }
- }
-
- if len(formErrors.Errors) > 0 {
- (*context.TemplateData)["FormError"] = formErrors
- (*context.TemplateData)["EntryForm"] = entry
- resp.WriteHeader(http.StatusBadRequest)
-
- return failure(context, req, resp)
- }
-
- return success(context, req, resp)
- }
-}
-
-func ListGuestbookContinuation(context *RequestContext, req *http.Request, resp http.ResponseWriter) ContinuationChain {
- return func(success Continuation, failure Continuation) ContinuationChain {
- entries, err := database.GetGuestbookEntries(context.DBConn)
- if err != nil {
- log.Println(err)
- resp.WriteHeader(http.StatusInternalServerError)
- return failure(context, req, resp)
- }
-
- (*context.TemplateData)["GuestbookEntries"] = entries
- return success(context, req, resp)
- }
-}