diff --git a/api/spyware.go b/api/spyware.go index 9230529..f8c000e 100644 --- a/api/spyware.go +++ b/api/spyware.go @@ -50,7 +50,7 @@ func (a *apiapp) Visit(w http.ResponseWriter, r *http.Request) { } else if err == http.ErrNoCookie { // Create cookie and send it log.Printf("No cookie sent by client, sending cookie to them!\n") - c = &http.Cookie{Name: "spyware", Value: uuid.NewString(), MaxAge: 0} + c = &http.Cookie{Name: "spyware", Value: uuid.NewString(), Path: "/", MaxAge: 0} http.SetCookie(w, c) } diff --git a/src/guestbook.go b/src/guestbook.go index 20c764b..d63b2b2 100644 --- a/src/guestbook.go +++ b/src/guestbook.go @@ -131,29 +131,37 @@ func (g guestbook) Render() app.UI { ), ).OnSubmit(func(ctx app.Context, e app.Event) { // This was to prevent the page from reloading + fmt.Println("Send clicked") e.PreventDefault() if g.name == "" || g.message == "" { fmt.Printf("Error: one or more field(s) are empty. For now unhandled\n") + g.gbErrorModalOpen = true + g.errorText = "One or more field(s) are empty. Fix that shit man." return } + fmt.Println("Nothing too empty") if len(g.name) > 40 || len(g.message) > 360 { fmt.Printf("Error: Your message is too long fucker\n") g.gbModalOpen = true return } + fmt.Println("Got through validity") var uuid string = "" - c := client.Jar.Cookies(app.Window().URL()) - for _, c2 := range c { - if c2.Name == "spyware" { - uuid = c2.Value - } - } - // Check if uuid is set, if it's not, then clearly the cookie does not exist - if uuid == "" { - uuid = "undetermined" - g.gbErrorModalOpen = true - return - } + // c := client.Jar.Cookies(app.Window().URL()) + // fmt.Println("Getting cookies") + // for _, c2 := range c { + // if c2.Name == "spyware" { + // uuid = c2.Value + // fmt.Println("Found spyware cookie") + // } + // } + // // Check if uuid is set, if it's not, then clearly the cookie does not exist + // if uuid == "" { + // uuid = "undetermined" + // g.errorText = "Failed sending message, couldn't insert UUID" + // g.gbErrorModalOpen = true + // return + // } g.OnSubmit(ctx, g.name, g.email, g.website, g.message, uuid) g.clear() @@ -173,7 +181,7 @@ func (g guestbook) Render() app.UI { g.gbErrorModalOpen, NewGuestbookAlertModal(). OnClose(func() { - g.gbModalOpen = false + g.gbErrorModalOpen = false g.Update() }). Text(fmt.Sprintf("Error placing comment: %s", g.errorText)), diff --git a/src/page.go b/src/page.go index f96c6e6..2d29912 100644 --- a/src/page.go +++ b/src/page.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/url" "github.com/maxence-charriere/go-app/v9/pkg/app" ) @@ -66,9 +67,17 @@ func (p *page) OnMount(ctx app.Context) { app.Logf("Error while creating vist request %s\n", err.Error()) } defer resp.Body.Close() + cook, err := resp.Request.Cookie("spyware") + if err != nil { + app.Logf("Error reading cookie from request: %s\n", err) + } + fmt.Printf("cook: %v\n", cook) - c := resp.Cookies() - fmt.Printf("c: %v\n", c) + ctx.Dispatch(func(ctx app.Context) { + fmt.Printf("jar: %v\n", jar) + c := client.Jar.Cookies(&url.URL{Host: app.Window().URL().Hostname()}) + fmt.Printf("c: %v\n", c) + }) }) }