Compare commits

..

2 Commits

Author SHA1 Message Date
49d9ff467a Improve compatibility with ancient browsers
All checks were successful
Backend Build and Test / build (push) Successful in 2m9s
2025-05-25 19:25:39 +02:00
56ea895cf8 Ignore more sqlite files 2025-05-25 19:25:39 +02:00
3 changed files with 21 additions and 2 deletions

1
backend/.gitignore vendored
View File

@ -1,3 +1,4 @@
*.db3
*.db3-*
*.db3.*
/allowance_planner

View File

@ -43,6 +43,11 @@ type ServerConfig struct {
Started chan bool
}
const DefaultDomain = "localhost:8080"
// The domain that the server is reachable at.
var domain = DefaultDomain
func getUsers(c *gin.Context) {
users, err := db.GetUsers()
if err != nil {
@ -650,5 +655,10 @@ func main() {
config.Datasource = "allowance_planner.db3"
log.Printf("Warning: No DB_PATH set, using default of %s", config.Datasource)
}
domain = os.Getenv("DOMAIN")
if domain == "" {
domain = DefaultDomain
log.Printf("Warning: No DOMAIN set, using default of %s", domain)
}
start(context.Background(), &config)
}

View File

@ -3,6 +3,7 @@ package main
import (
"errors"
"github.com/gin-gonic/gin"
"log"
"net/http"
"strconv"
)
@ -26,11 +27,17 @@ func loadWebEndpoints(router *gin.Engine) {
router.GET("/completeAllowance", renderCompleteAllowance)
}
func redirectToPage(c *gin.Context, page string) {
scheme := c.Request.URL.Scheme
c.Redirect(http.StatusSeeOther, scheme+domain+page)
}
func renderLogin(c *gin.Context) {
if c.Query("user") != "" {
c.SetCookie("user", c.Query("user"), 3600, "/", "localhost", false, true)
log.Println("Set cookie for user:", c.Query("user"))
c.SetCookie("user", c.Query("user"), 3600, "", "", false, true)
}
c.Redirect(http.StatusFound, "/")
redirectToPage(c, "/")
}
func renderIndex(c *gin.Context) {
@ -149,6 +156,7 @@ func renderCompleteAllowance(c *gin.Context) {
func getCurrentUser(c *gin.Context) *int {
currentUserStr, err := c.Cookie("user")
log.Println("Cookie string:", currentUserStr)
if errors.Is(err, http.ErrNoCookie) {
renderNoUser(c)
return nil