Small fixes user authorization
This commit is contained in:
parent
8604fab2d4
commit
92eac70c0b
2 changed files with 60 additions and 13 deletions
|
@ -816,6 +816,49 @@ class PlexAPI():
|
||||||
dprint(__name__, 1, "====== MyPlex sign out XML finished ======")
|
dprint(__name__, 1, "====== MyPlex sign out XML finished ======")
|
||||||
dprint(__name__, 0, 'MyPlex Sign Out done')
|
dprint(__name__, 0, 'MyPlex Sign Out done')
|
||||||
|
|
||||||
|
def UserAccessRestricted(self, username):
|
||||||
|
"""
|
||||||
|
Returns True if the user's access is restricted (parental restrictions)
|
||||||
|
False otherwise.
|
||||||
|
|
||||||
|
Returns False also if access cannot be checked because plex.tv cannot
|
||||||
|
be reached.
|
||||||
|
"""
|
||||||
|
plexToken = utils.settings('plexToken')
|
||||||
|
users = self.MyPlexListHomeUsers(plexToken)
|
||||||
|
# If an error is encountered, set to False
|
||||||
|
if not users:
|
||||||
|
self.logMsg("Could not check user access restrictions.", 1)
|
||||||
|
self.logMsg("Setting restrictions to False.", 1)
|
||||||
|
return False
|
||||||
|
for user in users:
|
||||||
|
if username in user['title']:
|
||||||
|
restricted = user['restricted']
|
||||||
|
if restricted == '1':
|
||||||
|
restricted = True
|
||||||
|
else:
|
||||||
|
restricted = False
|
||||||
|
self.logMsg("Successfully checked user parental access for %s: restricted access is set to %s" % (username, restricted), 1)
|
||||||
|
return restricted
|
||||||
|
|
||||||
|
def GetUserArtworkURL(self, username):
|
||||||
|
"""
|
||||||
|
Returns the URL for the user's Avatar. Or False if something went
|
||||||
|
wrong.
|
||||||
|
"""
|
||||||
|
plexToken = utils.settings('plexToken')
|
||||||
|
users = self.MyPlexListHomeUsers(plexToken)
|
||||||
|
# If an error is encountered, set to False
|
||||||
|
if not users:
|
||||||
|
self.logMsg("Could not get userlist from plex.tv.", 1)
|
||||||
|
self.logMsg("No URL for user avatar.", 1)
|
||||||
|
return False
|
||||||
|
for user in users:
|
||||||
|
if username in user['title']:
|
||||||
|
url = user['thumb']
|
||||||
|
self.logMsg("Avatar url for user %s is: %s" % (username, url), 1)
|
||||||
|
return url
|
||||||
|
|
||||||
def ChoosePlexHomeUser(self):
|
def ChoosePlexHomeUser(self):
|
||||||
"""
|
"""
|
||||||
Let's user choose from a list of Plex home users. Will switch to that
|
Let's user choose from a list of Plex home users. Will switch to that
|
||||||
|
@ -825,6 +868,8 @@ class PlexAPI():
|
||||||
username
|
username
|
||||||
userid
|
userid
|
||||||
authtoken
|
authtoken
|
||||||
|
|
||||||
|
Will return empty strings if failed.
|
||||||
"""
|
"""
|
||||||
string = self.__language__
|
string = self.__language__
|
||||||
plexToken = utils.settings('plexToken')
|
plexToken = utils.settings('plexToken')
|
||||||
|
@ -891,6 +936,7 @@ class PlexAPI():
|
||||||
trials += trials
|
trials += trials
|
||||||
if not username:
|
if not username:
|
||||||
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)
|
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)
|
||||||
|
return ('', '', '', '')
|
||||||
return (username, user['id'], usertoken)
|
return (username, user['id'], usertoken)
|
||||||
|
|
||||||
def MyPlexSwitchHomeUser(self, id, pin, authtoken, options={}):
|
def MyPlexSwitchHomeUser(self, id, pin, authtoken, options={}):
|
||||||
|
|
|
@ -201,18 +201,18 @@ class UserClient(threading.Thread):
|
||||||
doUtils = self.doUtils
|
doUtils = self.doUtils
|
||||||
art = artwork.Artwork()
|
art = artwork.Artwork()
|
||||||
|
|
||||||
url = "{server}/emby/Users/{UserId}?format=json"
|
url = PlexAPI.PlexAPI().GetUserArtworkURL(self.currUser)
|
||||||
result = doUtils.downloadUrl(url)
|
if url:
|
||||||
|
result = doUtils.downloadUrl(url, authenticate=False)
|
||||||
self.userSettings = result
|
self.userSettings = result
|
||||||
# Set user image for skin display
|
# Set user image for skin display
|
||||||
if result.get('PrimaryImageTag'):
|
if result.get('PrimaryImageTag'):
|
||||||
utils.window('EmbyUserImage', value=art.getUserArtwork(result['Id'], 'Primary'))
|
utils.window('EmbyUserImage', value=art.getUserArtwork(result['Id'], 'Primary'))
|
||||||
|
|
||||||
# Set resume point max
|
# Set resume point max
|
||||||
url = "{server}/emby/System/Configuration?format=json"
|
# url = "{server}/emby/System/Configuration?format=json"
|
||||||
result = doUtils.downloadUrl(url)
|
# result = doUtils.downloadUrl(url)
|
||||||
|
|
||||||
utils.settings('markPlayed', value=str(result['MaxResumePct']))
|
# utils.settings('markPlayed', value=str(result['MaxResumePct']))
|
||||||
|
|
||||||
def getPublicUsers(self):
|
def getPublicUsers(self):
|
||||||
|
|
||||||
|
@ -286,7 +286,8 @@ class UserClient(threading.Thread):
|
||||||
doUtils.setToken(self.currToken)
|
doUtils.setToken(self.currToken)
|
||||||
doUtils.setSSL(self.ssl, self.sslcert)
|
doUtils.setSSL(self.ssl, self.sslcert)
|
||||||
# parental control - let's verify if access is restricted
|
# parental control - let's verify if access is restricted
|
||||||
self.hasAccess()
|
# self.hasAccess()
|
||||||
|
|
||||||
# Start DownloadUtils session
|
# Start DownloadUtils session
|
||||||
doUtils.startSession()
|
doUtils.startSession()
|
||||||
self.getAdditionalUsers()
|
self.getAdditionalUsers()
|
||||||
|
|
Loading…
Reference in a new issue