From f35e35e1dec8ae0255e5e8090bc746613e9575a6 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Sun, 25 May 2025 19:25:17 +0200 Subject: [PATCH 1/3] Ignore more sqlite files --- backend/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/.gitignore b/backend/.gitignore index 23487f5..83e7943 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ *.db3 *.db3-* +*.db3.* /allowance_planner -- 2.47.2 From 16749887511f1b48df2a6afcdf4c14f8a1d1ca6a Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Sun, 25 May 2025 19:25:28 +0200 Subject: [PATCH 2/3] Improve compatibility with ancient browsers --- backend/main.go | 10 ++++++++++ backend/web.go | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/main.go b/backend/main.go index d18c841..c1481a2 100644 --- a/backend/main.go +++ b/backend/main.go @@ -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 { @@ -706,5 +711,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) } diff --git a/backend/web.go b/backend/web.go index 820e89e..e9c5687 100644 --- a/backend/web.go +++ b/backend/web.go @@ -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 -- 2.47.2 From 8d43f3828adad16409c9cec9f7ae31413125a6f4 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Thu, 29 May 2025 13:51:38 +0200 Subject: [PATCH 3/3] Stuff now works better on IE2 --- backend/allowance_planner.db3.backup.3 | Bin 20480 -> 20480 bytes backend/web.go | 17 +++++++++++------ backend/web.gohtml | 8 +++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/backend/allowance_planner.db3.backup.3 b/backend/allowance_planner.db3.backup.3 index b7a3e07efe5659750b9e90bca8d0238b13edb321..380cafd58d06ed547fc988be1d29f3fda77d7c53 100644 GIT binary patch delta 521 zcmaiv!D|yi7{$MDvLWg2PQJDwtYNceR#CeULW>7aqEZkMgo1y7#AFf|H`$uqJ@nSJ z;MJBniqN|!>0jX8;>n}Of>1Bwp4HiHdUkGac<=YVw||2BCwSzdaopK%8PI7%Q6vt;~cf0X=*Art26H@3z5V@8@65-q^B%um$s8FFn3KyzrJh4|<+tKbC z6Tu}xltU2`5*GwWh!f%hJ#g%WUJzA;s(Jv#k*eu|Q+c!T+WDxGo+_fgNp`(& z{%>a9`_0TD&d#aVPWZ7BORcaWV^JZ4gfTKB1R=zL%YrK{`q@kk_@r=YpS_Af#?O{L z?@MB4Hwd4}eUjbqbUQ3a00|%gB!C2v01`j~NB{{uAOh=-VHZb6==-N*c_vUY2wEN4 zTvSp2$vpo0-0b|En4f*|#GL5Yd(KhM5m5Z9@SCx!sZgwhenW<4r_&P$E|EK;?EJmSIiByuT9WM`7L(onJIb%sV-Z4H zy%9WTOf0s7Ry*9)zPvVM+Qnj#uICdNv5c0ZQSQP#W3xz(o{?{$lL$TZHjTgkOgn79@ZKkN^@u0!RP}AOR$R1dsp{KmthM|4x82iwsfY zmG;t7pbYxbdj)Ed5o(-LDpIPUf@Q~edmggjLm9T|b!@={yO8^r@Z0=P{wx2PU*O;I zulc9^L%zxb{uV#UXL*H>@<+K1Zdi~25D$s^*6K>yaLrW8Uxl%Z zuA~hYz8Oezt>j;T4&iG79Y$h!ToKBr37<}Xa+h7?v7!FfNA!SsJs*+s&XC^(p{>u{=jxcZ?H4JL7S$NsM z4(C{6H~>H{o`hdE{NvyJ17gu5R?jQ#@a2{awAcB7O^~}!AJPtt+5K*6;4pb@^4j$6 zN>U0pet>ECTzhR9OnZ&r9KXrrXTM3%-=#$e#$@vl#Iw5pbAK>$r;>m2F%w1@g0?2p zZN${n!qfsIzhAVW)f_E?a+re4Q%U!4tR%-5bdaUEG-zbbd51T17=Xcd33%`VK+z!8s3WT+>%a>D1x942 HN`Cqey07IF diff --git a/backend/web.go b/backend/web.go index e9c5687..d8188e1 100644 --- a/backend/web.go +++ b/backend/web.go @@ -28,8 +28,13 @@ func loadWebEndpoints(router *gin.Engine) { } func redirectToPage(c *gin.Context, page string) { + redirectToPageStatus(c, page, http.StatusSeeOther) +} + +func redirectToPageStatus(c *gin.Context, page string, status int) { scheme := c.Request.URL.Scheme - c.Redirect(http.StatusSeeOther, scheme+domain+page) + target := scheme + domain + page + c.Redirect(status, target) } func renderLogin(c *gin.Context) { @@ -75,7 +80,7 @@ func renderCreateTask(c *gin.Context) { return } - c.Redirect(http.StatusFound, "/") + redirectToPageStatus(c, "/", http.StatusFound) } func renderCompleteTask(c *gin.Context) { @@ -92,7 +97,7 @@ func renderCompleteTask(c *gin.Context) { return } - c.Redirect(http.StatusFound, "/") + redirectToPageStatus(c, "/", http.StatusFound) } func renderCreateAllowance(c *gin.Context) { @@ -129,7 +134,7 @@ func renderCreateAllowance(c *gin.Context) { return } - c.Redirect(http.StatusFound, "/") + redirectToPageStatus(c, "/", http.StatusFound) } func renderCompleteAllowance(c *gin.Context) { @@ -151,7 +156,7 @@ func renderCompleteAllowance(c *gin.Context) { return } - c.Redirect(http.StatusFound, "/") + redirectToPageStatus(c, "/", http.StatusFound) } func getCurrentUser(c *gin.Context) *int { @@ -180,7 +185,7 @@ func getCurrentUser(c *gin.Context) *int { func unsetUserCookie(c *gin.Context) { c.SetCookie("user", "", -1, "/", "localhost", false, true) - c.Redirect(http.StatusFound, "/") + redirectToPageStatus(c, "/", http.StatusFound) } func renderNoUser(c *gin.Context) { diff --git a/backend/web.gohtml b/backend/web.gohtml index 1ed49ee..cd23150 100644 --- a/backend/web.gohtml +++ b/backend/web.gohtml @@ -3,9 +3,11 @@ Allowance Planner 2000 @@ -27,7 +29,7 @@ {{if ne .CurrentUser 0}}

Allowances

- +
@@ -43,7 +45,7 @@ - + {{range .Allowances}} {{if eq .ID 0}} @@ -103,7 +105,7 @@ - +
Name
-- 2.47.2