feat: go to room on create/login
This commit is contained in:
parent
cdd31e186a
commit
8bb1509786
|
@ -131,10 +131,10 @@ func createRoomHandler(templateFs *embed.FS,
|
||||||
PasswordHash: r.PostFormValue("personalPassword"), // TODO hash the password, not to store
|
PasswordHash: r.PostFormValue("personalPassword"), // TODO hash the password, not to store
|
||||||
}
|
}
|
||||||
newRoom := rooms.Room{
|
newRoom := rooms.Room{
|
||||||
Name: roomName,
|
Name: roomName,
|
||||||
PasswordHash: r.PostFormValue("roomPassword"), // TODO hash the password, not to store
|
PasswordHash: r.PostFormValue("roomPassword"), // TODO hash the password, not to store
|
||||||
AdminIds: []rooms.PersonId{person.Id},
|
AdminIds: []rooms.PersonId{person.Id},
|
||||||
Paricipants: []rooms.PersonId{person.Id},
|
Paricipants: []rooms.PersonId{person.Id},
|
||||||
AllKnownPeople: map[rooms.PersonId]rooms.Person{
|
AllKnownPeople: map[rooms.PersonId]rooms.Person{
|
||||||
person.Id: person},
|
person.Id: person},
|
||||||
}
|
}
|
||||||
|
@ -155,9 +155,7 @@ func createRoomHandler(templateFs *embed.FS,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
})
|
})
|
||||||
w.Header().Add("HX-Retarget", "body")
|
w.Header().Add("HX-Redirect", fmt.Sprintf("/room/%s", newRoom.Name))
|
||||||
w.Header().Add("HX-Push-Url", "/")
|
|
||||||
renderIndexPage(newSession, w)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +241,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
err := roomsM.Update(r.Context(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
err := roomsM.Update(r.Context(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||||
log.Printf("/login/join about to modify room %+v", fromRoom)
|
log.Printf("/login/join about to modify room %+v", fromRoom)
|
||||||
toRoom = fromRoom
|
toRoom = fromRoom
|
||||||
toRoom.AllKnownPeople[person.Id] = person
|
toRoom.AllKnownPeople[person.Id] = person
|
||||||
log.Printf("/login/join will save %+v", toRoom)
|
log.Printf("/login/join will save %+v", toRoom)
|
||||||
return toRoom
|
return toRoom
|
||||||
})
|
})
|
||||||
|
@ -275,23 +273,23 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
return // error sitting a new person
|
return // error sitting a new person
|
||||||
}
|
}
|
||||||
|
|
||||||
newSessionId, err := sessionSM.Save(r.Context(), room.Name, person.Id)
|
newSession, err := sessionSM.Save(r.Context(), room.Name, person.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("/login/submit > error saving session %s", err)
|
log.Printf("/login/submit > error saving session %s", err)
|
||||||
}
|
}
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: authCookieName,
|
Name: authCookieName,
|
||||||
Value: fmt.Sprint(newSessionId),
|
Value: fmt.Sprint(newSession.SessionId),
|
||||||
Secure: true,
|
Secure: true,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
})
|
})
|
||||||
log.Printf("is is %d. room things %s & %s, personal things %s and %s. \n found room %+v",
|
log.Printf("is is %+v. room things %s & %s, personal things %s and %s. \n found room %+v",
|
||||||
newSessionId, roomName, roomPass, personName, personPass, room,
|
newSession, roomName, roomPass, personName, personPass, room,
|
||||||
)
|
)
|
||||||
// TODO render what? index page with some data passed?
|
// TODO render what? index page with some data passed?
|
||||||
// or, what? i could just redirect to / for now
|
// or, what? i could just redirect to / for now
|
||||||
w.Header().Add("HX-Redirect", "/")
|
w.Header().Add("HX-Redirect", fmt.Sprintf("/room/%s", newSession.RoomId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue