From d1a90359e63785dee66fe17d0d044f318f7e19e3 Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 5 Jun 2024 23:18:24 +0200 Subject: [PATCH] vingo: add settings --- vingo/handlers/settings.go | 33 +++++++++++++++++++++++++++++++++ vingo/layouts/settings.html | 30 +++++++++++++++++++++++++++++- vingo/main.go | 1 + 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 vingo/handlers/settings.go diff --git a/vingo/handlers/settings.go b/vingo/handlers/settings.go new file mode 100644 index 0000000..ebd0e42 --- /dev/null +++ b/vingo/handlers/settings.go @@ -0,0 +1,33 @@ +package handlers + +import ( + "vingo/database" + + "github.com/gofiber/fiber/v2" +) + +func SettingsUpdate(c *fiber.Ctx) error { + user := getUserFromStore(c) + + scan_in_out := c.FormValue("scan_in_out") + leaderboard := c.FormValue("leaderboard") + public := c.FormValue("public") + + if scan_in_out == "" || leaderboard == "" || public == "" { + return c.Status(400).SendString("Missing fields") + } + + settings := database.Settings{ + ScanInOut: scan_in_out == "on", + Leaderboard: leaderboard == "on", + Public: public == "on", + } + + sess, _ := store.Get(c) + database.UpdateSettings(user.Id, settings) + user, _ = database.GetUser(user.Id) + sess.Set(STORE_USER, &user) + sess.Save() + + return c.Redirect("/settings") +} diff --git a/vingo/layouts/settings.html b/vingo/layouts/settings.html index 67c8a40..9173a9c 100644 --- a/vingo/layouts/settings.html +++ b/vingo/layouts/settings.html @@ -1 +1,29 @@ -This is where settings should go \ No newline at end of file +

+ Yay! Settings! They don't do anything :( +

+ +
+ + + + +
+ + \ No newline at end of file diff --git a/vingo/main.go b/vingo/main.go index e4dddc8..8e080cf 100644 --- a/vingo/main.go +++ b/vingo/main.go @@ -49,6 +49,7 @@ func main() { logged.Get("/leaderboard", handlers.Leaderboard) logged.Get("/settings", handlers.Settings) + logged.Post("/settings", handlers.SettingsUpdate) } // Admin routes