From 44e8947329b44ce82245eb97ffad3e0b00b4b000 Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 23 Mar 2019 18:08:22 -0400 Subject: [PATCH] Print the new modes and pins to the console - When the access mode changes, print the new mode (and pin, if applicable) to the server console. - Don't return an HTTP error when getting a session fails, just make a new session. - Save pins to the settings --- chatcommands.go | 3 +++ handlers.go | 3 +-- settings.go | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/chatcommands.go b/chatcommands.go index b4b5927..e938d92 100644 --- a/chatcommands.go +++ b/chatcommands.go @@ -335,6 +335,7 @@ var commands = &CommandControl{ switch AccessMode(strings.ToLower(args[0])) { case AccessOpen: settings.RoomAccess = AccessOpen + fmt.Println("[access] Room set to open") return "Room access set to open" case AccessPin: @@ -351,10 +352,12 @@ var commands = &CommandControl{ } } settings.RoomAccess = AccessPin + fmt.Println("[access] Room set to pin: " + settings.RoomAccessPin) return "Room access set to Pin: " + settings.RoomAccessPin case AccessRequest: settings.RoomAccess = AccessRequest + fmt.Println("[access] Room set to request") return "Room access set to request. WARNING: this isn't implemented yet." default: diff --git a/handlers.go b/handlers.go index ae9aa93..f8bf85e 100644 --- a/handlers.go +++ b/handlers.go @@ -157,9 +157,8 @@ func wsHandler(w http.ResponseWriter, r *http.Request) { func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool { session, err := sstore.Get(r, "moviesession") if err != nil { + // Don't return as server error here, just make a new session. fmt.Printf("Unable to get session for client %s: %v\n", r.RemoteAddr, err) - http.Error(w, "Unable to get session data", http.StatusInternalServerError) - return false } if settings.RoomAccess == AccessPin { diff --git a/settings.go b/settings.go index 28f6926..22a7d6d 100644 --- a/settings.go +++ b/settings.go @@ -226,5 +226,8 @@ func (s *Settings) generateNewPin() (string, error) { return "", err } settings.RoomAccessPin = fmt.Sprintf("%04d", num) + if err = s.Save(); err != nil { + return "", err + } return settings.RoomAccessPin, nil }