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 +