feat: toggling Create/Join room button
This commit is contained in:
@@ -26,8 +26,8 @@ func registerLoginRoutes(
|
||||
}
|
||||
})
|
||||
|
||||
// submitting the login info : room name & pwd, personal name & pwd
|
||||
http.HandleFunc("/login/submit", func(w http.ResponseWriter, r *http.Request) {
|
||||
// when the room exists - attempt to join
|
||||
http.HandleFunc("/login/join", func(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@@ -38,7 +38,7 @@ func registerLoginRoutes(
|
||||
pn := r.PostFormValue("personalName")
|
||||
pp := r.PostFormValue("personalPassword")
|
||||
|
||||
room, err := rooms.Get(rn)
|
||||
room, _, err := rooms.Get(rn)
|
||||
if err != nil {
|
||||
log.Printf("/login/submit error getting room %s", rn)
|
||||
// return i guess
|
||||
@@ -63,6 +63,30 @@ func registerLoginRoutes(
|
||||
// d) how should i monitor sessions?
|
||||
})
|
||||
|
||||
// checking whether the room name already exists - change button between Join or Create
|
||||
// when room does not exist
|
||||
http.HandleFunc("/login/create", func(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
fmt.Fprintf(w, "got submitted form %+v", r.PostForm)
|
||||
})
|
||||
|
||||
// checking whether the room name already exists
|
||||
// toggle button between Join or Create
|
||||
http.HandleFunc("/login/room-name-check", func(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
roomName := r.PostFormValue("roomName")
|
||||
_, isFound, err := rooms.Get(roomName)
|
||||
if err != nil {
|
||||
log.Printf("/login/room-name-check error finding room %s\n", err)
|
||||
}
|
||||
var templFile = "templates/login.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templateFs, templFile))
|
||||
err = tmpl.ExecuteTemplate(w, "formButton", isFound)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user