jf-roku/source/api/userauth.brs

85 lines
2.3 KiB
Plaintext
Raw Normal View History

function get_token(user as String, password as String)
url = "Users/AuthenticateByName?format=json"
req = APIRequest(url)
encPass = CreateObject("roUrlTransfer")
json = postJson(req, FormatJson({ "Username": user, "Pw": password }))
if json = invalid then return invalid
2019-04-20 17:40:06 +00:00
userdata = CreateObject("roSGNode", "UserData")
userdata.json = json
userdata.callFunc("setActive")
userdata.callFunc("saveToRegistry")
return userdata
end function
function AboutMe()
2019-04-20 17:40:06 +00:00
id = get_setting("active_user")
url = Substitute("Users/{0}", id)
resp = APIRequest(url)
return getJson(resp)
end function
2019-03-19 04:17:50 +00:00
function SignOut()
if get_setting("active_user") <> invalid
unset_user_setting("token")
end if
2019-03-19 04:17:50 +00:00
unset_setting("active_user")
2020-03-08 05:56:05 +00:00
m.overhang.currentUser = ""
m.overhang.showOptions = false
m.scene.unobserveField("optionsPressed")
2019-03-19 04:17:50 +00:00
end function
2019-04-20 17:54:24 +00:00
function AvailableUsers()
users = parseJson(get_setting("available_users", "[]"))
return users
end function
function PickUser(id as string)
this_user = invalid
for each user in AvailableUsers()
if user.id = id then this_user = user
end for
if this_user = invalid then return invalid
set_setting("active_user", this_user.id)
set_setting("server", this_user.server)
end function
function RemoveUser(id as string)
user = CreateObject("roSGNode", "UserData")
user.id = id
user.callFunc("removeFromRegistry")
if get_setting("active_user") = id then SignOut()
end function
2019-04-20 17:54:24 +00:00
function ServerInfo()
url = "System/Info/Public"
resp = APIRequest(url)
return getJson(resp)
end function
function GetPublicUsers()
url = "Users/Public"
resp = APIRequest(url)
return getJson(resp)
end function
' Load and parse Display Settings from server
sub LoadUserPreferences()
id = get_setting("active_user")
' 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
url = Substitute("DisplayPreferences/usersettings?userId={0}&client=emby", id)
resp = APIRequest(url)
jsonResponse = getJson(resp)
if jsonResponse <> invalid and jsonResponse.CustomPrefs <> invalid and jsonResponse.CustomPrefs["landing-livetv"] <> invalid then
set_user_setting("display.livetv.landing", jsonResponse.CustomPrefs["landing-livetv"])
else
unset_user_setting("display.livetv.landing")
end if
end sub