feat: saving person pass across logout/rejoin
This commit is contained in:
@@ -116,7 +116,8 @@ func createRoomHandler(templateFs *embed.FS,
|
||||
Name: roomName,
|
||||
PasswordHash: r.PostFormValue("roomPassword"), // TODO hash the password, not to store
|
||||
AdminIds: []rooms.PersonId{person.Id},
|
||||
Paricipants: []rooms.Person{person},
|
||||
Paricipants: []rooms.PersonId{person.Id},
|
||||
AllKnownPeople: []rooms.Person{person},
|
||||
}
|
||||
err = roomsM.Save(newRoom)
|
||||
if err != nil {
|
||||
@@ -188,7 +189,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
log.Printf("/login/join error getting room %s", roomName)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
// TODO render error to be put in error place
|
||||
return
|
||||
return // no such room
|
||||
} else {
|
||||
log.Printf("/login/submit found room %+v", room)
|
||||
}
|
||||
@@ -198,11 +199,11 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
log.Printf("/login/join bad room pass for %+v", room)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
// TODO render error to be put in error place
|
||||
return
|
||||
return // bad room password
|
||||
}
|
||||
|
||||
var person rooms.Person
|
||||
for _, participant := range room.Paricipants {
|
||||
for _, participant := range room.AllKnownPeople {
|
||||
if participant.Name == personName {
|
||||
person = participant
|
||||
}
|
||||
@@ -214,7 +215,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
log.Printf("/login/join bad person pass for %+s", person.Name)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
// TODO render error to be put in error place
|
||||
return
|
||||
return // bad person password
|
||||
}
|
||||
// person joining for thethe first time
|
||||
if (person == rooms.Person{}) {
|
||||
@@ -227,7 +228,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
}
|
||||
err := roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
toRoom = fromRoom
|
||||
toRoom.Paricipants = append(toRoom.Paricipants, person)
|
||||
toRoom.AllKnownPeople = append(toRoom.AllKnownPeople, person)
|
||||
return toRoom
|
||||
})
|
||||
if err != nil {
|
||||
@@ -235,13 +236,25 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
// TODO render error to be put in error place
|
||||
// with message try again
|
||||
return
|
||||
return // error adding New person
|
||||
}
|
||||
}
|
||||
// TODO handle context and cancells, with separate function that writeds new updated room
|
||||
// now we have room and person, can create a session
|
||||
// and we've checked password
|
||||
|
||||
err = roomsM.Update(context.TODO(), room.Name, func(fromRoom rooms.Room) (toRoom rooms.Room) {
|
||||
toRoom.Paricipants = append(toRoom.Paricipants, person.Id)
|
||||
return toRoom
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("/login/join problem sitting joining person at a table %+v", person.Name)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
// TODO render error to be put in error place
|
||||
// with message try again
|
||||
return // error sitting a new person
|
||||
}
|
||||
|
||||
newSessionId, err := sessionSM.Save(room.Name, person.Id)
|
||||
if err != nil {
|
||||
log.Printf("/login/submit > error saving session %s", err)
|
||||
|
||||
Reference in New Issue
Block a user