From 8070becd846a5b59b0ee32015d02eb00a2652f4e Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 20 Jan 2022 16:03:08 -0800 Subject: bowl: :star: --- web.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 web.go (limited to 'web.go') diff --git a/web.go b/web.go new file mode 100644 index 0000000..b6ccf48 --- /dev/null +++ b/web.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/gin-gonic/gin" +) + +func mountRoutes(router *gin.Engine) { + router.GET("/", func(c *gin.Context) { + c.HTML(http.StatusOK, "index.tmpl", map[string]interface{}{}) + }) + + router.POST("/api/v1/entry", func(c *gin.Context) { + formType := c.PostForm("type") + formNotes := c.PostForm("notes") + formAccessCode := c.PostForm("access_code") + + if formAccessCode == accessCode { + log.Println(formType, formNotes, formAccessCode) + + write(formType, formNotes, c.ClientIP()) + + c.HTML(http.StatusOK, "notice.tmpl", map[string]interface{}{ + "Notice": "submission successfully logged", + "Data": fmt.Sprintf("{ type: \"%s\", notes: \"%s\" }", formType, formNotes), + }) + } else { + log.Printf("invalid access code: %s, expected: %s\n", formAccessCode, accessCode) + + c.HTML(http.StatusUnauthorized, "notice.tmpl", map[string]interface{}{ + "Notice": "invalid access code", + }) + } + }) +} -- cgit v1.2.3