53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
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
|
|
|
|
}
|