mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-06-16 21:26:14 +00:00
Revert "Revert "Adjusted the rest to use the new method""
This reverts commit f8632a97d8
.
This commit is contained in:
parent
f8632a97d8
commit
78acae377f
6 changed files with 153 additions and 281 deletions
|
@ -19,18 +19,22 @@ from DownloadUtils import DownloadUtils
|
|||
|
||||
class UserClient(threading.Thread):
|
||||
|
||||
# Borg - multiple instances, shared state
|
||||
_shared_state = {}
|
||||
|
||||
clientInfo = ClientInformation()
|
||||
doUtils = DownloadUtils()
|
||||
KodiMonitor = KodiMonitor.Kodi_Monitor()
|
||||
|
||||
addonName = clientInfo.getAddonName()
|
||||
className = None
|
||||
addonId = clientInfo.getAddonId()
|
||||
addon = xbmcaddon.Addon(id=addonId)
|
||||
WINDOW = xbmcgui.Window(10000)
|
||||
|
||||
stopClient = False
|
||||
logLevel = 0
|
||||
addon = None
|
||||
auth = True
|
||||
retry = 0
|
||||
WINDOW = xbmcgui.Window(10000)
|
||||
|
||||
currUser = None
|
||||
currUserId = None
|
||||
|
@ -40,10 +44,7 @@ class UserClient(threading.Thread):
|
|||
|
||||
def __init__(self, *args):
|
||||
|
||||
self.KodiMonitor = KodiMonitor.Kodi_Monitor()
|
||||
|
||||
self.addonId = self.clientInfo.getAddonId()
|
||||
self.addon = xbmcaddon.Addon(id=self.addonId)
|
||||
self.__dict__ = self._shared_state
|
||||
self.className = self.__class__.__name__
|
||||
|
||||
threading.Thread.__init__(self, *args)
|
||||
|
@ -55,7 +56,7 @@ class UserClient(threading.Thread):
|
|||
def getUsername(self):
|
||||
|
||||
username = self.addon.getSetting('username')
|
||||
|
||||
|
||||
if (username == ""):
|
||||
self.logMsg("No username saved.", 2)
|
||||
return ""
|
||||
|
@ -136,18 +137,19 @@ class UserClient(threading.Thread):
|
|||
|
||||
# Get public Users
|
||||
url = "%s/mediabrowser/Users/Public?format=json" % server
|
||||
jsonData = self.doUtils.downloadUrl(url, authenticate=False)
|
||||
result = self.doUtils.downloadUrl(url, authenticate=False)
|
||||
|
||||
users = []
|
||||
|
||||
if (jsonData != ""):
|
||||
users = json.loads(jsonData)
|
||||
if (result != ""):
|
||||
users = result
|
||||
|
||||
return users
|
||||
|
||||
def loadCurrUser(self):
|
||||
|
||||
WINDOW = self.WINDOW
|
||||
doUtils = self.doUtils
|
||||
username = self.getUsername()
|
||||
|
||||
# Only to be used if token exists
|
||||
|
@ -162,6 +164,14 @@ class UserClient(threading.Thread):
|
|||
WINDOW.setProperty("server_%s" % username, self.getServer(prefix=False))
|
||||
WINDOW.setProperty("userId%s" % username, self.currUserId)
|
||||
|
||||
# Set DownloadUtils values
|
||||
doUtils.setUsername(username)
|
||||
doUtils.setUserId(self.currUserId)
|
||||
doUtils.setServer(self.currServer)
|
||||
doUtils.setToken(self.currToken)
|
||||
# Start DownloadUtils session
|
||||
doUtils.startSession()
|
||||
|
||||
self.currUser = username
|
||||
|
||||
def authenticate(self):
|
||||
|
@ -195,11 +205,15 @@ class UserClient(threading.Thread):
|
|||
users = self.getPublicUsers()
|
||||
password = ""
|
||||
|
||||
'''if users == "":
|
||||
self.WINDOW.setProperty("Server_status", "Stop")
|
||||
return'''
|
||||
# Find user in list
|
||||
for user in users:
|
||||
name = user.get("Name")
|
||||
name = user[u'Name']
|
||||
userHasPassword = False
|
||||
if (username == name):
|
||||
|
||||
if (unicode(username, 'utf-8') in name):
|
||||
# Verify if user has a password
|
||||
if (user.get("HasPassword") == True):
|
||||
userHasPassword = True
|
||||
|
@ -207,7 +221,7 @@ class UserClient(threading.Thread):
|
|||
if (userHasPassword):
|
||||
password = xbmcgui.Dialog().input("Enter password for user: %s" % username, option=xbmcgui.ALPHANUM_HIDE_INPUT)
|
||||
# If password dialog is cancelled
|
||||
if password == "":
|
||||
if (password == ""):
|
||||
self.logMsg("No password entered.", 0)
|
||||
self.WINDOW.setProperty("Server_status", "Stop")
|
||||
self.auth = False
|
||||
|
@ -222,22 +236,21 @@ class UserClient(threading.Thread):
|
|||
|
||||
# Authenticate username and password
|
||||
url = "%s/mediabrowser/Users/AuthenticateByName?format=json" % server
|
||||
messageData = "username=%s&password=%s" % (username, sha1)
|
||||
data = {'username': username, 'password': sha1}
|
||||
self.logMsg(data, 2)
|
||||
|
||||
resp = self.doUtils.downloadUrl(url, postBody=messageData, type="POST", authenticate=False)
|
||||
result = self.doUtils.downloadUrl(url, postBody=data, type="POST", authenticate=False)
|
||||
|
||||
result = None
|
||||
accessToken = None
|
||||
try:
|
||||
self.logMsg("Auth_Reponse: %s" % resp, 1)
|
||||
result = json.loads(resp)
|
||||
accessToken = result.get("AccessToken")
|
||||
self.logMsg("Auth_Reponse: %s" % result, 1)
|
||||
accessToken = result[u'AccessToken']
|
||||
except:
|
||||
pass
|
||||
|
||||
if (result != None and accessToken != None):
|
||||
self.currUser = username
|
||||
userId = result.get("User").get("Id")
|
||||
userId = result[u'User'][u'Id']
|
||||
addon.setSetting("accessToken%s" % username, accessToken)
|
||||
addon.setSetting("userId%s" % username, userId)
|
||||
self.logMsg("User Authenticated: %s" % accessToken)
|
||||
|
@ -249,7 +262,7 @@ class UserClient(threading.Thread):
|
|||
self.logMsg("User authentication failed.")
|
||||
addon.setSetting("accessToken%s" % username, "")
|
||||
addon.setSetting("userId%s" % username, "")
|
||||
xbmcgui.Dialog().ok("Error Connecting", "Wrong password.")
|
||||
xbmcgui.Dialog().ok("Error connecting", "Invalid username or password.")
|
||||
|
||||
# Give two attempts at entering password
|
||||
self.retry += 1
|
||||
|
@ -262,7 +275,7 @@ class UserClient(threading.Thread):
|
|||
|
||||
def resetClient(self):
|
||||
|
||||
if self.currToken != None:
|
||||
if (self.currToken != None):
|
||||
# In case of 401, removed saved token
|
||||
self.addon.setSetting("accessToken%s" % self.currUser, "")
|
||||
self.WINDOW.setProperty("accessToken%s" % self.currUser, "")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue