feat: create|login on room path
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
type LoginSectionData struct {
|
||||
IsRoomExisting bool
|
||||
RoomName string
|
||||
}
|
||||
type loginPageData struct {
|
||||
LoginSection LoginSectionData
|
||||
@@ -33,7 +34,7 @@ func registerLoginRoutes(
|
||||
) {
|
||||
// login page
|
||||
http.HandleFunc(loginPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
renderLoginPage(w)
|
||||
renderLoginPage(w, "")
|
||||
})
|
||||
http.HandleFunc("/login/join", joinRoomHandler(templateFs, sessionSM, roomsM))
|
||||
http.HandleFunc("/login/create", createRoomHandler(templateFs, sessionSM, roomsM))
|
||||
@@ -86,7 +87,7 @@ func authedPageMiddleware(
|
||||
returnNoAccess := func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("auth middle > restricting access to %s", r.URL.Path)
|
||||
w.Header().Add("HX-Replace-Url", loginPath)
|
||||
renderLoginPage(w)
|
||||
renderLoginPage(w, "")
|
||||
}
|
||||
rerturnSuccess := func(w http.ResponseWriter, r *http.Request, session sessions.SessionData) {
|
||||
ctx := context.WithValue(r.Context(), contextKey("session"), session)
|
||||
@@ -105,18 +106,24 @@ func authedPageMiddleware(
|
||||
})
|
||||
}
|
||||
|
||||
func renderLoginPage(w http.ResponseWriter) {
|
||||
func renderLoginPage(w http.ResponseWriter, roomName string) {
|
||||
baseFile := "templates/base.gohtml"
|
||||
pageTempl := "templates/login.gohtml"
|
||||
loginSecion := "templates/login-section.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templateFs, pageTempl, baseFile, loginSecion))
|
||||
|
||||
title := "Some Automoderation: Join room or create one"
|
||||
if roomName != "" {
|
||||
title = fmt.Sprintf("Some Automoderation: create or join '%s' room", roomName)
|
||||
}
|
||||
data := pageData{
|
||||
Base: baseData{
|
||||
Title: "login",
|
||||
Title: title,
|
||||
},
|
||||
Content: loginPageData{
|
||||
LoginSection: LoginSectionData{
|
||||
IsRoomExisting: false,
|
||||
RoomName: roomName,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user