mirror of
https://github.com/jellyfin/jellyfin-roku.git
synced 2024-11-27 08:20:47 +00:00
auto update user.friendlyName and api auth header when user.name is updated
This commit is contained in:
parent
8874b61781
commit
3f172dc3e8
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user