For now disable sending UUID with comment
continuous-integration/drone/push Build was killed Details

This commit is contained in:
DutchEllie 2022-06-25 12:13:40 +02:00
parent eb21ce6d8e
commit e932269f04
Signed by: DutchEllie
SSH Key Fingerprint: SHA256:dKq6ZSgN5E3Viqrw/+xAdf2VdR6hdRGNyrYqXXwfjTY
3 changed files with 33 additions and 16 deletions

View File

@ -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)
}

View File

@ -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)),

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"net/url"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
@ -66,10 +67,18 @@ 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()
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)
})
})
}