Skip to content

Commit

Permalink
vingo: add settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-dev committed Jun 16, 2024
1 parent 86c57f7 commit d1a9035
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
33 changes: 33 additions & 0 deletions vingo/handlers/settings.go
Original file line number Diff line number Diff line change
@@ -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")
}
30 changes: 29 additions & 1 deletion vingo/layouts/settings.html
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
This is where settings should go
<h1 class="title">
Yay! Settings! They don't do anything :(
</h1>

<form class="settings" action="/settings" method="post" autocomplete="off">
<label>
<input type="checkbox" name="scan_in_out" {{ if .user.Settings.ScanInOut }} checked {{ end }}>
<input type='hidden' value='off' name='scan_in_out'>
Keep track of time based on scan-in and scan-out (experimental)
</label>
<label>
<input type="checkbox" name="leaderboard" {{ if .user.Settings.Leaderboard }} checked {{ end }}>
<input type='hidden' value='off' name='leaderboard'>
Show on leaderboard
</label>
<label>
<input type="checkbox" name="public" {{ if .user.Settings.Public }} checked {{ end }}>
<input type='hidden' value='off' name='public'>
(Semi-)Public profile
</label>
<input type="submit" value="Save settings">
</form>

<style>
.settings {
display: flex;
flex-direction: column;
}
</style>
1 change: 1 addition & 0 deletions vingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {
logged.Get("/leaderboard", handlers.Leaderboard)

logged.Get("/settings", handlers.Settings)
logged.Post("/settings", handlers.SettingsUpdate)
}

// Admin routes
Expand Down

0 comments on commit d1a9035

Please sign in to comment.