diff options
| author | Fuwn <[email protected]> | 2022-01-20 16:03:08 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-20 16:03:08 -0800 |
| commit | 8070becd846a5b59b0ee32015d02eb00a2652f4e (patch) | |
| tree | e4bb4d40792d75bcb7649ca56b36239753489ad0 /web.go | |
| download | bowl-8070becd846a5b59b0ee32015d02eb00a2652f4e.tar.xz bowl-8070becd846a5b59b0ee32015d02eb00a2652f4e.zip | |
bowl: :star:
Diffstat (limited to 'web.go')
| -rw-r--r-- | web.go | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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", + }) + } + }) +} |