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
This commit is contained in:
Zorchenhimer 2019-03-23 18:08:22 -04:00
parent 7448876299
commit 44e8947329
3 changed files with 7 additions and 2 deletions

View File

@ -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:

View File

@ -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 {

View File

@ -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
}