Merge pull request #1640 from cewert/fix-saved-credentials

This commit is contained in:
Charles Ewert 2024-01-12 17:28:45 -05:00 committed by GitHub
commit 5aa26f39aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 14 deletions

View File

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

View File

@ -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 LCase(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 LCase(key) = "name"
session.user.SetServerDeviceName()
end if
end sub
' Update the global session after user is authenticated.
@ -187,23 +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()
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
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 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
@ -372,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
@ -383,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.