diff --git a/flake.nix b/flake.nix index 068b04f..983de92 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,7 @@ pkgs.semgrep pkgs.gopls pkgs.nodePackages.tailwindcss + pkgs.nodePackages.prettier pkgs.gnumake ]; shellHook = '' diff --git a/main.go b/main.go index 31ac437..b092b35 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,9 @@ import ( "fmt" "log" "net/http" + "sunshine.industries/some-automoderation/routes" + "sunshine.industries/some-automoderation/sessions" ) func main() { @@ -15,7 +17,8 @@ func main() { fmt.Printf("Server will start on port %d\n", port) - routes.RegisterRoutes() + sessions := sessions.DummySM{} + routes.RegisterRoutes(&sessions) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) } diff --git a/routes/login_page.go b/routes/login_page.go new file mode 100644 index 0000000..eda7722 --- /dev/null +++ b/routes/login_page.go @@ -0,0 +1,52 @@ +package routes + +import ( + "embed" + "fmt" + "html/template" + "log" + "net/http" + + "sunshine.industries/some-automoderation/sessions" +) + +func registerLoginRoutes(templateFs *embed.FS, sessions *sessions.DummySM) { + // login page + http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) { + var templFile = "templates/login.gohtml" + tmpl := template.Must(template.ParseFS(templateFs, templFile)) + err := tmpl.Execute(w, nil) + if err != nil { + log.Printf("my error in executing template, huh\n %s", err) + } + }) + + // submitting the login info : room name & pwd, personal name & pwd + http.HandleFunc("/login/submit", func(w http.ResponseWriter, r *http.Request) { + err := r.ParseForm() + if err != nil { + w.WriteHeader(http.StatusBadRequest) + } + + rn := r.PostFormValue("roomName") + rp := r.PostFormValue("roomPassword") + pn := r.PostFormValue("personalName") + pp := r.PostFormValue("personalPassword") + + roomId := 1 // would be taken from rooms interface from redis + // would be either taken from room info on correct person pass or created + personId := 111 + sessions.Save(int64(roomId), int64(personId)) + + fmt.Fprintf(w, "room things %s & %s, personal things %s and %s", rn, rp, pn, pp) + // i suppose here i'll need to + // a) check if room password OK + // b) get room data + // c) check if such person exists, + // either create one, or check password + // d) how should i monitor sessions? + }) + + // checking whether the room name already exists - change button between Join or Create + +} diff --git a/routes/routes.go b/routes/routes.go index 41c00b5..cce3740 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -5,6 +5,8 @@ import ( "html/template" "log" "net/http" + + "sunshine.industries/some-automoderation/sessions" ) //go:embed templates @@ -13,13 +15,15 @@ var templateFs embed.FS //go:embed static var staticFilesFs embed.FS -func RegisterRoutes() { +func RegisterRoutes(sessions *sessions.DummySM) { + // login page + registerLoginRoutes(&templateFs, sessions) // main page template http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { var templFile = "templates/index.gohtml" tmpl := template.Must(template.ParseFS(templateFs, templFile)) - err := tmpl.Execute(w, 15) + err := tmpl.Execute(w, nil) if err != nil { log.Printf("my error in executing template, huh\n %s", err) } diff --git a/routes/static/out.css b/routes/static/out.css index 23f9e02..8496e92 100644 --- a/routes/static/out.css +++ b/routes/static/out.css @@ -534,11 +534,76 @@ video { --tw-backdrop-sepia: ; } +.col-span-full { + grid-column: 1 / -1; +} + +.flex { + display: flex; +} + +.grid { + display: grid; +} + +.h-full { + height: 100%; +} + +.h-screen { + height: 100vh; +} + +.grid-cols-2 { + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + +.grid-rows-\[auto\2c 1fr\] { + grid-template-rows: auto 1fr; +} + +.flex-col { + flex-direction: column; +} + +.place-content-center { + place-content: center; +} + +.gap-4 { + gap: 1rem; +} + +.gap-6 { + gap: 1.5rem; +} + +.rounded { + border-radius: 0.25rem; +} + +.border { + border-width: 1px; +} + +.border-black { + --tw-border-opacity: 1; + border-color: rgb(0 0 0 / var(--tw-border-opacity)); +} + .bg-amber-400 { --tw-bg-opacity: 1; background-color: rgb(251 191 36 / var(--tw-bg-opacity)); } +.bg-main-700\/25 { + background-color: rgb(194 65 12 / 0.25); +} + +.p-4 { + padding: 1rem; +} + .text-xl { font-size: 1.25rem; line-height: 1.75rem; diff --git a/routes/templates/index.gohtml b/routes/templates/index.gohtml index e62ea0f..8446c1a 100644 --- a/routes/templates/index.gohtml +++ b/routes/templates/index.gohtml @@ -1,29 +1,35 @@ -
- - -This is index
- +This is index
+ diff --git a/routes/templates/login.gohtml b/routes/templates/login.gohtml new file mode 100644 index 0000000..3c7e970 --- /dev/null +++ b/routes/templates/login.gohtml @@ -0,0 +1,80 @@ + + + + + +