From 8874b617811d62c3a1fe03af565a2231e50d2b51 Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Fri, 12 Jan 2024 15:49:20 -0500 Subject: [PATCH 1/4] fix saved credentials bug #1636 --- source/utils/session.bs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/utils/session.bs b/source/utils/session.bs index 71fe1fbf..505e7b3d 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -192,11 +192,16 @@ namespace session ' Sets the global server device name value used by the API sub SetServerDeviceName() + ' default value is the unique id for the device + deviceName = m.global.device.id if isValid(m.global.session.user) and isValid(m.global.session.user.friendlyName) - m.global.device.serverDeviceName = m.global.device.id + m.global.session.user.friendlyName - else - m.global.device.serverDeviceName = m.global.device.id + deviceName = deviceName + m.global.session.user.friendlyName end if + + ' update the global device array + tmpDevice = m.global.device + tmpDevice.AddReplace("serverDeviceName", deviceName) + m.global.setFields({ device: tmpDevice }) end sub ' Load and parse Display Settings from server From 3f172dc3e89298648dbea2c5828cbef5face86ac Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Fri, 12 Jan 2024 16:16:35 -0500 Subject: [PATCH 2/4] auto update user.friendlyName and api auth header when user.name is updated --- source/ShowScenes.bs | 6 ++---- source/utils/session.bs | 44 ++++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/source/ShowScenes.bs b/source/ShowScenes.bs index 3610b249..6c030947 100644 --- a/source/ShowScenes.bs +++ b/source/ShowScenes.bs @@ -92,8 +92,7 @@ function LoginFlow() startLoadingSpinner() print "A public user was selected with username=" + userSelected session.user.Update("name", userSelected) - regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "") - session.user.Update("friendlyName", regex.ReplaceAll(userSelected, "")) + ' save userid to session for each user in publicUsersNodes if user.name = userSelected @@ -159,8 +158,7 @@ function LoginFlow() print "Auth token found in registry" session.user.Update("authToken", myAuthToken) session.user.Update("name", myUsername) - regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "") - session.user.Update("friendlyName", regex.ReplaceAll(myUsername, "")) + print "Attempting to use API with auth token" currentUser = AboutMe() if currentUser = invalid diff --git a/source/utils/session.bs b/source/utils/session.bs index 505e7b3d..79d7e1a6 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -119,12 +119,25 @@ namespace session sub Update(key as string, value as dynamic) ' validate parameters if key = "" or value = invalid then return + ' make copy of global user session tmpSessionUser = m.global.session.user ' update the temp user array tmpSessionUser[key] = value + + ' keep friendlyName in sync + if key = "name" + regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "") + tmpSessionUser["friendlyName"] = regex.ReplaceAll(value, "") + end if + ' update global user session using the temp array session.Update("user", tmpSessionUser) + + ' keep auth header in sync + if key = "name" + session.user.SetServerDeviceName() + end if end sub ' Update the global session after user is authenticated. @@ -187,28 +200,32 @@ namespace session set_setting("active_user", tmpSession.user.id) end if + ' Save device id so we don't calculate it every time we need it + session.user.SetServerDeviceName() + ' Load user preferences from server session.user.LoadUserPreferences() end sub ' Sets the global server device name value used by the API sub SetServerDeviceName() - ' default value is the unique id for the device - deviceName = m.global.device.id - if isValid(m.global.session.user) and isValid(m.global.session.user.friendlyName) - deviceName = deviceName + m.global.session.user.friendlyName + localGlobal = m.global + + ' default device name is the unique id for the device + deviceName = localGlobal.device.id + if isValid(localGlobal.session.user) and isValid(localGlobal.session.user.friendlyName) + deviceName = deviceName + localGlobal.session.user.friendlyName end if - ' update the global device array - tmpDevice = m.global.device - tmpDevice.AddReplace("serverDeviceName", deviceName) - m.global.setFields({ device: tmpDevice }) + ' update global if needed + if localGlobal.device.serverDeviceName <> deviceName + tmpDevice = localGlobal.device + tmpDevice.AddReplace("serverDeviceName", deviceName) + m.global.setFields({ device: tmpDevice }) + end if end sub ' Load and parse Display Settings from server sub LoadUserPreferences() - ' Save device id so we don't calculate it every time we need it - session.user.SetServerDeviceName() - id = m.global.session.user.id ' Currently using client "emby", which is what website uses so we get same Display prefs as web. ' May want to change to specific Roku display settings @@ -377,6 +394,8 @@ namespace session ' load globals session.user.settings.LoadGlobals() + ' Reset server device name state + session.user.SetServerDeviceName() end sub ' Grab global vars from registry and overwrite defaults @@ -388,9 +407,6 @@ namespace session session.user.settings.Save(item, get_setting(item)) end if end for - - ' Reset server device name state - session.user.SetServerDeviceName() end sub ' Saves the user setting to the global session. From 03941b4d77da1ca9d81a2d15b76637f32d5c1fbd Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Fri, 12 Jan 2024 17:05:25 -0500 Subject: [PATCH 3/4] Update source/utils/session.bs --- source/utils/session.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/utils/session.bs b/source/utils/session.bs index 79d7e1a6..3e8ce4f0 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -126,7 +126,7 @@ namespace session tmpSessionUser[key] = value ' keep friendlyName in sync - if key = "name" + if LCase(key) = "name" regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "") tmpSessionUser["friendlyName"] = regex.ReplaceAll(value, "") end if From e2be70f90bf248688ced8f6f75be1a6a538871d4 Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Fri, 12 Jan 2024 17:05:57 -0500 Subject: [PATCH 4/4] Update source/utils/session.bs --- source/utils/session.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/utils/session.bs b/source/utils/session.bs index 3e8ce4f0..497ff310 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -135,7 +135,7 @@ namespace session session.Update("user", tmpSessionUser) ' keep auth header in sync - if key = "name" + if LCase(key) = "name" session.user.SetServerDeviceName() end if end sub