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()
|
startLoadingSpinner()
|
||||||
print "A public user was selected with username=" + userSelected
|
print "A public user was selected with username=" + userSelected
|
||||||
session.user.Update("name", userSelected)
|
session.user.Update("name", userSelected)
|
||||||
regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "")
|
|
||||||
session.user.Update("friendlyName", regex.ReplaceAll(userSelected, ""))
|
|
||||||
' save userid to session
|
' save userid to session
|
||||||
for each user in publicUsersNodes
|
for each user in publicUsersNodes
|
||||||
if user.name = userSelected
|
if user.name = userSelected
|
||||||
|
@ -159,8 +158,7 @@ function LoginFlow()
|
||||||
print "Auth token found in registry"
|
print "Auth token found in registry"
|
||||||
session.user.Update("authToken", myAuthToken)
|
session.user.Update("authToken", myAuthToken)
|
||||||
session.user.Update("name", myUsername)
|
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"
|
print "Attempting to use API with auth token"
|
||||||
currentUser = AboutMe()
|
currentUser = AboutMe()
|
||||||
if currentUser = invalid
|
if currentUser = invalid
|
||||||
|
|
|
@ -119,12 +119,25 @@ namespace session
|
||||||
sub Update(key as string, value as dynamic)
|
sub Update(key as string, value as dynamic)
|
||||||
' validate parameters
|
' validate parameters
|
||||||
if key = "" or value = invalid then return
|
if key = "" or value = invalid then return
|
||||||
|
|
||||||
' make copy of global user session
|
' make copy of global user session
|
||||||
tmpSessionUser = m.global.session.user
|
tmpSessionUser = m.global.session.user
|
||||||
' update the temp user array
|
' update the temp user array
|
||||||
tmpSessionUser[key] = value
|
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
|
' update global user session using the temp array
|
||||||
session.Update("user", tmpSessionUser)
|
session.Update("user", tmpSessionUser)
|
||||||
|
|
||||||
|
' keep auth header in sync
|
||||||
|
if key = "name"
|
||||||
|
session.user.SetServerDeviceName()
|
||||||
|
end if
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
' Update the global session after user is authenticated.
|
' Update the global session after user is authenticated.
|
||||||
|
@ -187,28 +200,32 @@ namespace session
|
||||||
set_setting("active_user", tmpSession.user.id)
|
set_setting("active_user", tmpSession.user.id)
|
||||||
end if
|
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()
|
session.user.LoadUserPreferences()
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
' Sets the global server device name value used by the API
|
' Sets the global server device name value used by the API
|
||||||
sub SetServerDeviceName()
|
sub SetServerDeviceName()
|
||||||
' default value is the unique id for the device
|
localGlobal = m.global
|
||||||
deviceName = m.global.device.id
|
|
||||||
if isValid(m.global.session.user) and isValid(m.global.session.user.friendlyName)
|
' default device name is the unique id for the device
|
||||||
deviceName = deviceName + m.global.session.user.friendlyName
|
deviceName = localGlobal.device.id
|
||||||
|
if isValid(localGlobal.session.user) and isValid(localGlobal.session.user.friendlyName)
|
||||||
|
deviceName = deviceName + localGlobal.session.user.friendlyName
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' update the global device array
|
' update global if needed
|
||||||
tmpDevice = m.global.device
|
if localGlobal.device.serverDeviceName <> deviceName
|
||||||
|
tmpDevice = localGlobal.device
|
||||||
tmpDevice.AddReplace("serverDeviceName", deviceName)
|
tmpDevice.AddReplace("serverDeviceName", deviceName)
|
||||||
m.global.setFields({ device: tmpDevice })
|
m.global.setFields({ device: tmpDevice })
|
||||||
|
end if
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
' Load and parse Display Settings from server
|
' Load and parse Display Settings from server
|
||||||
sub LoadUserPreferences()
|
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
|
id = m.global.session.user.id
|
||||||
' Currently using client "emby", which is what website uses so we get same Display prefs as web.
|
' 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
|
' May want to change to specific Roku display settings
|
||||||
|
@ -377,6 +394,8 @@ namespace session
|
||||||
|
|
||||||
' load globals
|
' load globals
|
||||||
session.user.settings.LoadGlobals()
|
session.user.settings.LoadGlobals()
|
||||||
|
' Reset server device name state
|
||||||
|
session.user.SetServerDeviceName()
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
' Grab global vars from registry and overwrite defaults
|
' Grab global vars from registry and overwrite defaults
|
||||||
|
@ -388,9 +407,6 @@ namespace session
|
||||||
session.user.settings.Save(item, get_setting(item))
|
session.user.settings.Save(item, get_setting(item))
|
||||||
end if
|
end if
|
||||||
end for
|
end for
|
||||||
|
|
||||||
' Reset server device name state
|
|
||||||
session.user.SetServerDeviceName()
|
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
' Saves the user setting to the global session.
|
' Saves the user setting to the global session.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user