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:
parent
7448876299
commit
44e8947329
|
@ -335,6 +335,7 @@ var commands = &CommandControl{
|
||||||
switch AccessMode(strings.ToLower(args[0])) {
|
switch AccessMode(strings.ToLower(args[0])) {
|
||||||
case AccessOpen:
|
case AccessOpen:
|
||||||
settings.RoomAccess = AccessOpen
|
settings.RoomAccess = AccessOpen
|
||||||
|
fmt.Println("[access] Room set to open")
|
||||||
return "Room access set to open"
|
return "Room access set to open"
|
||||||
|
|
||||||
case AccessPin:
|
case AccessPin:
|
||||||
|
@ -351,10 +352,12 @@ var commands = &CommandControl{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings.RoomAccess = AccessPin
|
settings.RoomAccess = AccessPin
|
||||||
|
fmt.Println("[access] Room set to pin: " + settings.RoomAccessPin)
|
||||||
return "Room access set to Pin: " + settings.RoomAccessPin
|
return "Room access set to Pin: " + settings.RoomAccessPin
|
||||||
|
|
||||||
case AccessRequest:
|
case AccessRequest:
|
||||||
settings.RoomAccess = AccessRequest
|
settings.RoomAccess = AccessRequest
|
||||||
|
fmt.Println("[access] Room set to request")
|
||||||
return "Room access set to request. WARNING: this isn't implemented yet."
|
return "Room access set to request. WARNING: this isn't implemented yet."
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -157,9 +157,8 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool {
|
func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool {
|
||||||
session, err := sstore.Get(r, "moviesession")
|
session, err := sstore.Get(r, "moviesession")
|
||||||
if err != nil {
|
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)
|
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 {
|
if settings.RoomAccess == AccessPin {
|
||||||
|
|
|
@ -226,5 +226,8 @@ func (s *Settings) generateNewPin() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
settings.RoomAccessPin = fmt.Sprintf("%04d", num)
|
settings.RoomAccessPin = fmt.Sprintf("%04d", num)
|
||||||
|
if err = s.Save(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
return settings.RoomAccessPin, nil
|
return settings.RoomAccessPin, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue