fix: display correct button on unauthed room page

This commit is contained in:
efim 2023-11-23 06:14:54 +00:00
parent f7def011f5
commit 550841e882
2 changed files with 5 additions and 5 deletions

View File

@ -34,7 +34,7 @@ func registerLoginRoutes(
) { ) {
// login page // login page
http.HandleFunc(loginPath, func(w http.ResponseWriter, r *http.Request) { http.HandleFunc(loginPath, func(w http.ResponseWriter, r *http.Request) {
renderLoginPage(w, "") renderLoginPage(w, "", false)
}) })
http.HandleFunc("/login/join", joinRoomHandler(templateFs, sessionSM, roomsM)) http.HandleFunc("/login/join", joinRoomHandler(templateFs, sessionSM, roomsM))
http.HandleFunc("/login/create", createRoomHandler(templateFs, sessionSM, roomsM)) http.HandleFunc("/login/create", createRoomHandler(templateFs, sessionSM, roomsM))
@ -107,7 +107,7 @@ func authedPageMiddleware(
}) })
} }
func renderLoginPage(w http.ResponseWriter, roomName string) { func renderLoginPage(w http.ResponseWriter, roomName string, isRoomExisting bool) {
baseFile := "templates/base.gohtml" baseFile := "templates/base.gohtml"
pageTempl := "templates/login.gohtml" pageTempl := "templates/login.gohtml"
loginSecion := "templates/login-section.gohtml" loginSecion := "templates/login-section.gohtml"
@ -123,7 +123,7 @@ func renderLoginPage(w http.ResponseWriter, roomName string) {
}, },
Content: loginPageData{ Content: loginPageData{
LoginSection: LoginSectionData{ LoginSection: LoginSectionData{
IsRoomExisting: false, IsRoomExisting: isRoomExisting,
RoomName: roomName, RoomName: roomName,
}, },
}, },

View File

@ -177,13 +177,13 @@ func roomPageRoute(
// check session, // check session,
session, err := getRequestSession(r, sessionSM) session, err := getRequestSession(r, sessionSM)
room, found, err := roomsM.Get(roomName)
if err != nil || session.RoomId != roomName { if err != nil || session.RoomId != roomName {
log.Printf("not authed with session %+v | error %s, but for wrong room, trying to access %s", session, err, roomName) log.Printf("not authed with session %+v | error %s, but for wrong room, trying to access %s", session, err, roomName)
renderLoginPage(w, roomName) renderLoginPage(w, roomName, found)
return return
} }
room, found, err := roomsM.Get(roomName)
if err != nil || !found { if err != nil || !found {
log.Printf("/room room for name %s not found or err: %s / found %t", roomName, err, found) log.Printf("/room room for name %s not found or err: %s / found %t", roomName, err, found)
// TODO here should be append to error place // TODO here should be append to error place