This commit is contained in:
SpootDev 2016-03-31 13:40:47 -05:00
parent 8a130fe810
commit 2748d21ff4

View file

@ -81,7 +81,6 @@ class UserClient(threading.Thread):
def getUserId(self): def getUserId(self):
log = self.logMsg
window = utils.window window = utils.window
settings = utils.settings settings = utils.settings
@ -94,17 +93,17 @@ class UserClient(threading.Thread):
if not s_userId: if not s_userId:
# Save access token if it's missing from settings # Save access token if it's missing from settings
settings('userId%s' % username, value=w_userId) settings('userId%s' % username, value=w_userId)
log("Returning userId from WINDOW for username: %s UserId: %s" self.logMsg("Returning userId from WINDOW for username: %s UserId: %s"
% (username, w_userId), 2) % (username, w_userId), 2)
return w_userId return w_userId
# Verify the settings # Verify the settings
elif s_userId: elif s_userId:
log("Returning userId from SETTINGS for username: %s userId: %s" self.logMsg("Returning userId from SETTINGS for username: %s userId: %s"
% (username, s_userId), 2) % (username, s_userId), 2)
return s_userId return s_userId
# No userId found # No userId found
else: else:
log("No userId saved for username: %s." % username, 1) self.logMsg("No userId saved for username: %s." % username, 1)
def getServer(self, prefix=True): def getServer(self, prefix=True):
@ -142,7 +141,6 @@ class UserClient(threading.Thread):
def getToken(self): def getToken(self):
log = self.logMsg
window = utils.window window = utils.window
settings = utils.settings settings = utils.settings
@ -156,17 +154,17 @@ class UserClient(threading.Thread):
if not s_token: if not s_token:
# Save access token if it's missing from settings # Save access token if it's missing from settings
settings('accessToken', value=w_token) settings('accessToken', value=w_token)
log("Returning accessToken from WINDOW for username: %s accessToken: %s" self.logMsg("Returning accessToken from WINDOW for username: %s accessToken: %s"
% (username, w_token), 2) % (username, w_token), 2)
return w_token return w_token
# Verify the settings # Verify the settings
elif s_token: elif s_token:
log("Returning accessToken from SETTINGS for username: %s accessToken: %s" self.logMsg("Returning accessToken from SETTINGS for username: %s accessToken: %s"
% (username, s_token), 2) % (username, s_token), 2)
window('emby_accessToken%s' % username, value=s_token) window('emby_accessToken%s' % username, value=s_token)
return s_token return s_token
else: else:
log("No token found.", 1) self.logMsg("No token found.", 1)
return "" return ""
def getSSLverify(self): def getSSLverify(self):
@ -229,7 +227,6 @@ class UserClient(threading.Thread):
def hasAccess(self): def hasAccess(self):
# hasAccess is verified in service.py # hasAccess is verified in service.py
log = self.logMsg
window = utils.window window = utils.window
url = "{server}/emby/Users?format=json" url = "{server}/emby/Users?format=json"
@ -237,7 +234,7 @@ class UserClient(threading.Thread):
if result == False: if result == False:
# Access is restricted, set in downloadutils.py via exception # Access is restricted, set in downloadutils.py via exception
log("Access is restricted.", 1) self.logMsg("Access is restricted.", 1)
self.HasAccess = False self.HasAccess = False
elif window('emby_online') != "true": elif window('emby_online') != "true":
@ -245,7 +242,7 @@ class UserClient(threading.Thread):
pass pass
elif window('emby_serverStatus') == "restricted": elif window('emby_serverStatus') == "restricted":
log("Access is granted.", 1) self.logMsg("Access is granted.", 1)
self.HasAccess = True self.HasAccess = True
window('emby_serverStatus', clear=True) window('emby_serverStatus', clear=True)
xbmcgui.Dialog().notification("Emby for Kodi", utils.language(33007)) xbmcgui.Dialog().notification("Emby for Kodi", utils.language(33007))
@ -301,7 +298,6 @@ class UserClient(threading.Thread):
def authenticate(self): def authenticate(self):
log = self.logMsg
lang = utils.language lang = utils.language
window = utils.window window = utils.window
settings = utils.settings settings = utils.settings
@ -316,12 +312,12 @@ class UserClient(threading.Thread):
# If there's no settings.xml # If there's no settings.xml
if not hasSettings: if not hasSettings:
log("No settings.xml found.", 1) self.logMsg("No settings.xml found.", 1)
self.auth = False self.auth = False
return return
# If no user information # If no user information
elif not server or not username: elif not server or not username:
log("Missing server information.", 1) self.logMsg("Missing server information.", 1)
self.auth = False self.auth = False
return return
# If there's a token, load the user # If there's a token, load the user
@ -331,9 +327,9 @@ class UserClient(threading.Thread):
if result == False: if result == False:
pass pass
else: else:
log("Current user: %s" % self.currUser, 1) self.logMsg("Current user: %s" % self.currUser, 1)
log("Current userId: %s" % self.currUserId, 1) self.logMsg("Current userId: %s" % self.currUserId, 1)
log("Current accessToken: %s" % self.currToken, 2) self.logMsg("Current accessToken: %s" % self.currToken, 2)
return return
##### AUTHENTICATE USER ##### ##### AUTHENTICATE USER #####
@ -353,7 +349,7 @@ class UserClient(threading.Thread):
option=xbmcgui.ALPHANUM_HIDE_INPUT) option=xbmcgui.ALPHANUM_HIDE_INPUT)
# If password dialog is cancelled # If password dialog is cancelled
if not password: if not password:
log("No password entered.", 0) self.logMsg("No password entered.", 0)
window('emby_serverStatus', value="Stop") window('emby_serverStatus', value="Stop")
self.auth = False self.auth = False
return return
@ -369,16 +365,16 @@ class UserClient(threading.Thread):
# Authenticate username and password # Authenticate username and password
url = "%s/emby/Users/AuthenticateByName?format=json" % server url = "%s/emby/Users/AuthenticateByName?format=json" % server
data = {'username': username, 'password': sha1} data = {'username': username, 'password': sha1}
log(data, 2) self.logMsg(data, 2)
result = self.doUtils.downloadUrl(url, postBody=data, type="POST", authenticate=False) result = self.doUtils.downloadUrl(url, postBody=data, type="POST", authenticate=False)
try: try:
log("Auth response: %s" % result, 1) self.logMsg("Auth response: %s" % result, 1)
accessToken = result['AccessToken'] accessToken = result['AccessToken']
except (KeyError, TypeError): except (KeyError, TypeError):
log("Failed to retrieve the api key.", 1) self.logMsg("Failed to retrieve the api key.", 1)
accessToken = None accessToken = None
if accessToken is not None: if accessToken is not None:
@ -388,19 +384,19 @@ class UserClient(threading.Thread):
userId = result['User']['Id'] userId = result['User']['Id']
settings('accessToken', value=accessToken) settings('accessToken', value=accessToken)
settings('userId%s' % username, value=userId) settings('userId%s' % username, value=userId)
log("User Authenticated: %s" % accessToken, 1) self.logMsg("User Authenticated: %s" % accessToken, 1)
self.loadCurrUser(authenticated=True) self.loadCurrUser(authenticated=True)
window('emby_serverStatus', clear=True) window('emby_serverStatus', clear=True)
self.retry = 0 self.retry = 0
else: else:
log("User authentication failed.", 1) self.logMsg("User authentication failed.", 1)
settings('accessToken', value="") settings('accessToken', value="")
settings('userId%s' % username, value="") settings('userId%s' % username, value="")
dialog.ok(lang(33001), lang(33009)) dialog.ok(lang(33001), lang(33009))
# Give two attempts at entering password # Give two attempts at entering password
if self.retry == 2: if self.retry == 2:
log("Too many retries. " self.logMsg("Too many retries. "
"You can retry by resetting attempts in the addon settings.", 1) "You can retry by resetting attempts in the addon settings.", 1)
window('emby_serverStatus', value="Stop") window('emby_serverStatus', value="Stop")
dialog.ok(lang(33001), lang(33010)) dialog.ok(lang(33001), lang(33010))
@ -410,9 +406,7 @@ class UserClient(threading.Thread):
def resetClient(self): def resetClient(self):
log = self.logMsg self.logMsg("Reset UserClient authentication.", 1)
log("Reset UserClient authentication.", 1)
userId = self.getUserId() userId = self.getUserId()
if self.currToken is not None: if self.currToken is not None:
@ -420,18 +414,17 @@ class UserClient(threading.Thread):
utils.settings('accessToken', value="") utils.settings('accessToken', value="")
utils.window('emby_accessToken%s' % userId, clear=True) utils.window('emby_accessToken%s' % userId, clear=True)
self.currToken = None self.currToken = None
log("User token has been removed.", 1) self.logMsg("User token has been removed.", 1)
self.auth = True self.auth = True
self.currUser = None self.currUser = None
def run(self): def run(self):
log = self.logMsg
window = utils.window window = utils.window
monitor = xbmc.Monitor() monitor = xbmc.Monitor()
log("----===## Starting UserClient ##===----", 0) self.logMsg("----===## Starting UserClient ##===----", 0)
while not monitor.abortRequested(): while not monitor.abortRequested():
@ -466,8 +459,8 @@ class UserClient(threading.Thread):
# The status Stop is for when user cancelled password dialog. # The status Stop is for when user cancelled password dialog.
if server and username and status != "Stop": if server and username and status != "Stop":
# Only if there's information found to login # Only if there's information found to login
log("Server found: %s" % server, 2) self.logMsg("Server found: %s" % server, 2)
log("Username found: %s" % username, 2) self.logMsg("Username found: %s" % username, 2)
self.auth = True self.auth = True
@ -480,7 +473,7 @@ class UserClient(threading.Thread):
break break
self.doUtils.stopSession() self.doUtils.stopSession()
log("##===---- UserClient Stopped ----===##", 0) self.logMsg("##===---- UserClient Stopped ----===##", 0)
def stopClient(self): def stopClient(self):
# When emby for kodi terminates # When emby for kodi terminates