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 { } else if err == http.ErrNoCookie {
// Create cookie and send it // Create cookie and send it
log.Printf("No cookie sent by client, sending cookie to them!\n") 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) http.SetCookie(w, c)
} }

View File

@ -131,29 +131,37 @@ func (g guestbook) Render() app.UI {
), ),
).OnSubmit(func(ctx app.Context, e app.Event) { ).OnSubmit(func(ctx app.Context, e app.Event) {
// This was to prevent the page from reloading // This was to prevent the page from reloading
fmt.Println("Send clicked")
e.PreventDefault() e.PreventDefault()
if g.name == "" || g.message == "" { if g.name == "" || g.message == "" {
fmt.Printf("Error: one or more field(s) are empty. For now unhandled\n") 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 return
} }
fmt.Println("Nothing too empty")
if len(g.name) > 40 || len(g.message) > 360 { if len(g.name) > 40 || len(g.message) > 360 {
fmt.Printf("Error: Your message is too long fucker\n") fmt.Printf("Error: Your message is too long fucker\n")
g.gbModalOpen = true g.gbModalOpen = true
return return
} }
fmt.Println("Got through validity")
var uuid string = "" var uuid string = ""
c := client.Jar.Cookies(app.Window().URL()) // c := client.Jar.Cookies(app.Window().URL())
for _, c2 := range c { // fmt.Println("Getting cookies")
if c2.Name == "spyware" { // for _, c2 := range c {
uuid = c2.Value // 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" // // Check if uuid is set, if it's not, then clearly the cookie does not exist
g.gbErrorModalOpen = true // if uuid == "" {
return // 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.OnSubmit(ctx, g.name, g.email, g.website, g.message, uuid)
g.clear() g.clear()
@ -173,7 +181,7 @@ func (g guestbook) Render() app.UI {
g.gbErrorModalOpen, g.gbErrorModalOpen,
NewGuestbookAlertModal(). NewGuestbookAlertModal().
OnClose(func() { OnClose(func() {
g.gbModalOpen = false g.gbErrorModalOpen = false
g.Update() g.Update()
}). }).
Text(fmt.Sprintf("Error placing comment: %s", g.errorText)), Text(fmt.Sprintf("Error placing comment: %s", g.errorText)),

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"net/url"
"github.com/maxence-charriere/go-app/v9/pkg/app" "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()) app.Logf("Error while creating vist request %s\n", err.Error())
} }
defer resp.Body.Close() 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("c: %v\n", c) fmt.Printf("jar: %v\n", jar)
c := client.Jar.Cookies(&url.URL{Host: app.Window().URL().Hostname()})
fmt.Printf("c: %v\n", c)
})
}) })
} }