diff --git a/cmd/web/playershandler.go b/cmd/web/playershandler.go
new file mode 100644
index 0000000..c12c023
--- /dev/null
+++ b/cmd/web/playershandler.go
@@ -0,0 +1,86 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/hculpan/areweplaying/pkg/data"
+)
+
+func addPlayerHandler(w http.ResponseWriter, r *http.Request) {
+ if !ValidateJWTFromCookie(r, appKey) {
+ http.Error(w, "Unauthorized", http.StatusUnauthorized)
+ return
+ }
+
+ r.ParseForm()
+ session, err := data.ReadSessionData()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ p := data.Player{
+ Name: r.FormValue("name"),
+ Email: r.FormValue("email"),
+ Gm: r.FormValue("gm") == "on",
+ Attending: "unknown",
+ }
+
+ if err := data.AddPlayer(session, p); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ http.Redirect(w, r, "/setup", http.StatusSeeOther)
+}
+
+func deletePlayerHandler(w http.ResponseWriter, r *http.Request) {
+ if !ValidateJWTFromCookie(r, appKey) {
+ http.Error(w, "Unauthorized", http.StatusUnauthorized)
+ return
+ }
+
+ r.ParseForm()
+ session, err := data.ReadSessionData()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ name := r.FormValue("name")
+ if err := data.DeletePlayer(session, name); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ http.Redirect(w, r, "/setup", http.StatusSeeOther)
+}
+
+func editPlayerHandler(w http.ResponseWriter, r *http.Request) {
+ if !ValidateJWTFromCookie(r, appKey) {
+ http.Error(w, "Unauthorized", http.StatusUnauthorized)
+ return
+ }
+
+ r.ParseForm()
+ session, err := data.ReadSessionData()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ originalName := r.FormValue("originalName")
+ updated := data.Player{
+ Name: r.FormValue("name"),
+ Email: r.FormValue("email"),
+ Gm: r.FormValue("gm") == "on",
+ Attending: r.FormValue("attending"),
+ }
+
+ if err := data.UpdatePlayer(session, originalName, updated); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ http.Redirect(w, r, "/setup", http.StatusSeeOther)
+}
diff --git a/cmd/web/routes.go b/cmd/web/routes.go
index 01c2b1d..3cbc0a5 100644
--- a/cmd/web/routes.go
+++ b/cmd/web/routes.go
@@ -48,6 +48,18 @@ func routes(r *chi.Mux) {
sendReminderHandler(w, r)
})
+ r.Post("/admin/players/add", func(w http.ResponseWriter, r *http.Request) {
+ addPlayerHandler(w, r)
+ })
+
+ r.Post("/admin/players/delete", func(w http.ResponseWriter, r *http.Request) {
+ deletePlayerHandler(w, r)
+ })
+
+ r.Post("/admin/players/edit", func(w http.ResponseWriter, r *http.Request) {
+ editPlayerHandler(w, r)
+ })
+
r.Get("/sessioninfo", func(w http.ResponseWriter, r *http.Request) {
session, dataErr := data.ReadSessionData()
if dataErr != nil {
diff --git a/cmd/web/templates/header_templ.go b/cmd/web/templates/header_templ.go
index c72a9f5..d79d245 100644
--- a/cmd/web/templates/header_templ.go
+++ b/cmd/web/templates/header_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -29,11 +29,11 @@ func Header() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Are We Playing?")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "Are We Playing?")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- return templ_7745c5c3_Err
+ return nil
})
}
diff --git a/cmd/web/templates/index_templ.go b/cmd/web/templates/index_templ.go
index d226c36..584c4ea 100644
--- a/cmd/web/templates/index_templ.go
+++ b/cmd/web/templates/index_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -29,7 +29,7 @@ func MainPage() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -37,11 +37,11 @@ func MainPage() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- return templ_7745c5c3_Err
+ return nil
})
}
diff --git a/cmd/web/templates/login_templ.go b/cmd/web/templates/login_templ.go
index becaca4..45a1485 100644
--- a/cmd/web/templates/login_templ.go
+++ b/cmd/web/templates/login_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -29,7 +29,7 @@ func Login() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -37,11 +37,11 @@ func Login() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- return templ_7745c5c3_Err
+ return nil
})
}
diff --git a/cmd/web/templates/pagebody_templ.go b/cmd/web/templates/pagebody_templ.go
index 1df621c..8aa7010 100644
--- a/cmd/web/templates/pagebody_templ.go
+++ b/cmd/web/templates/pagebody_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -33,7 +33,7 @@ func PageBody(session data.Session) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Next Session: ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
Next Session: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -46,45 +46,45 @@ func PageBody(session data.Session) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
| Attending | Player |
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "| Attending | Player |
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, player := range session.Players {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" hx-swap=\"innerHTML\" hx-target=\"#session-info\" hx-trigger=\"click\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if player.Attending == "yes" {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else if player.Attending == "no" {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " | ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -97,17 +97,17 @@ func PageBody(session data.Session) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" |
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if session.Status == "planned" {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Status: ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "
Status: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -120,12 +120,12 @@ func PageBody(session data.Session) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else if session.Status == "canceled" {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Status: ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "
Status: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -138,12 +138,12 @@ func PageBody(session data.Session) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Status: ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "
Status: ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -156,16 +156,16 @@ func PageBody(session data.Session) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- return templ_7745c5c3_Err
+ return nil
})
}
diff --git a/cmd/web/templates/save_setup_templ.go b/cmd/web/templates/save_setup_templ.go
index 27f84b3..4d4e34c 100644
--- a/cmd/web/templates/save_setup_templ.go
+++ b/cmd/web/templates/save_setup_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -29,7 +29,7 @@ func SaveSetup(status string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -37,7 +37,7 @@ func SaveSetup(status string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -50,11 +50,11 @@ func SaveSetup(status string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- return templ_7745c5c3_Err
+ return nil
})
}
diff --git a/cmd/web/templates/sendemail_templ.go b/cmd/web/templates/sendemail_templ.go
index 2ed3e3f..c4d73c7 100644
--- a/cmd/web/templates/sendemail_templ.go
+++ b/cmd/web/templates/sendemail_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -29,7 +29,7 @@ func SendEmail(status string, msg string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -37,7 +37,7 @@ func SendEmail(status string, msg string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -50,7 +50,7 @@ func SendEmail(status string, msg string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -63,11 +63,11 @@ func SendEmail(status string, msg string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- return templ_7745c5c3_Err
+ return nil
})
}
diff --git a/cmd/web/templates/sendreminder_templ.go b/cmd/web/templates/sendreminder_templ.go
index 8f5df17..843dfcb 100644
--- a/cmd/web/templates/sendreminder_templ.go
+++ b/cmd/web/templates/sendreminder_templ.go
@@ -1,6 +1,6 @@
// Code generated by templ - DO NOT EDIT.
-// templ: version: v0.2.778
+// templ: version: v0.3.1020
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
@@ -29,7 +29,7 @@ func SendReminder(to string, subject string, text, msg string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -37,33 +37,33 @@ func SendReminder(to string, subject string, text, msg string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("