feat: create|login on room path
This commit is contained in:
parent
c8f28bf0de
commit
d87c102d95
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -25,9 +25,7 @@ func registerPageRoutes(
|
|||
roomsM rooms.RoomManager,
|
||||
) {
|
||||
http.Handle(roomPath, // ending in / captures all following path sections, i.e room name
|
||||
authedPageMiddleware(
|
||||
sessionSM,
|
||||
http.StripPrefix(roomPath, roomPageRoute(templateFs, roomsM))))
|
||||
http.StripPrefix(roomPath, roomPageRoute(templateFs, roomsM, sessionSM)))
|
||||
|
||||
http.Handle(raiseHandPath, // ending in / captures all following path sections, i.e gesture num
|
||||
authedPageMiddleware(
|
||||
|
@ -165,6 +163,7 @@ func releaseHandRoute(
|
|||
func roomPageRoute(
|
||||
templateFs *embed.FS,
|
||||
roomsM rooms.RoomManager,
|
||||
sessionSM sessions.SessionManagement,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
roomName := r.URL.Path
|
||||
|
@ -176,24 +175,16 @@ func roomPageRoute(
|
|||
}
|
||||
|
||||
// check session,
|
||||
session, found := getContextSession(r.Context())
|
||||
if !found {
|
||||
log.Printf("session not found %t", found)
|
||||
// TODO here will be rendering of
|
||||
// 'create this room' or 'join this room'
|
||||
// but yeah, let's just use auth middle that redirects to /
|
||||
w.Header().Add("HX-Redirect", "/")
|
||||
return
|
||||
}
|
||||
if session.RoomId != roomName {
|
||||
log.Printf("session found %+v, but for wrong room, trying to access %s", session, roomName)
|
||||
w.Header().Add("HX-Redirect", "/")
|
||||
session, err := getRequestSession(r, sessionSM)
|
||||
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)
|
||||
renderLoginPage(w, roomName)
|
||||
return
|
||||
}
|
||||
|
||||
room, found, err := roomsM.Get(roomName)
|
||||
if err != nil || !found {
|
||||
log.Printf("/room room for name %s not found or err: %s / found %s", 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
|
||||
w.Header().Add("HX-Redirect", "/")
|
||||
return
|
||||
|
|
|
@ -773,3 +773,11 @@ video {
|
|||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(185 28 28 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.read-only\:font-bold:-moz-read-only {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.read-only\:font-bold:read-only {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,16 @@
|
|||
id="roomName"
|
||||
type="text"
|
||||
name="roomName"
|
||||
value=""
|
||||
placeholder="room name!!!"
|
||||
value="{{.RoomName}}"
|
||||
placeholder="room name"
|
||||
hx-trigger="keyup changed delay:500ms"
|
||||
hx-post="/login/room-name-check"
|
||||
hx-target="#formButton"
|
||||
hx-swap="outerHTML"
|
||||
class="invalid:bg-red-700"
|
||||
class="invalid:bg-red-700 read-only:font-bold"
|
||||
{{ if not (eq .RoomName "") }}
|
||||
readonly
|
||||
{{ end }}
|
||||
/>
|
||||
<input
|
||||
id="roomPassword"
|
||||
|
|
Loading…
Reference in New Issue