Update token/user for connect module

This commit is contained in:
angelblue05 2016-09-09 18:12:30 -05:00
parent 0635990d67
commit 9411ff14ce
4 changed files with 20 additions and 22 deletions

View file

@ -645,26 +645,6 @@ class ConnectionManager(object):
return result
def onAuthenticated(self, result, options={}):
credentials = self.credentialProvider.getCredentials()
for s in credentials['Servers']:
if s['Id'] == result['ServerId']:
server = s
break
else: # Server not found?
return
if options.get('updateDateLastAccessed') is not False:
server['DateLastAccessed'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
server['UserId'] = result['User']['Id']
server['AccessToken'] = result['AccessToken']
self.credentialProvider.addOrUpdateServer(credentials['Servers'], server)
self._saveUserInfoIntoCredentials(server, result['User'])
self.credentialProvider.getCredentials(credentials)
def _onConnectUserSignIn(self, user):
self.connectUser = user

View file

@ -177,3 +177,7 @@ class ConnectManager(object):
return user
else:
raise RuntimeError("User is not authenticated")
def update_token(self, servers, server):
self._connect.credentialProvider.addOrUpdateServer(servers, server)
self.update_state()

View file

@ -91,10 +91,15 @@ class InitialSetup(object):
if settings('server'):
current_state = self.connectmanager.get_state()
for server in current_state['Servers']:
if server['Id'] == settings('serverId'):
# Update token
server['UserId'] = settings('userId') or None
server['AccessToken'] = settings('token') or None
self.connectmanager.update_token(current_state['Servers'], server)
server_address = self.connectmanager.get_address(server)
self._set_server(server_address, server)
#self._set_user(server['UserId'], server['AccessToken'])
log.info("Found server!")
return True

View file

@ -39,6 +39,7 @@ class UserClient(threading.Thread):
self.doutils = downloadutils.DownloadUtils()
self.download = self.doutils.downloadUrl
self.emby = embyserver.Read_EmbyServer()
self.connectmanager = connectmanager.ConnectManager()
threading.Thread.__init__(self)
@ -180,7 +181,7 @@ class UserClient(threading.Thread):
user_found = user
break
try:
user = connectmanager.ConnectManager().login_manual(server, user_found)
user = self.connectmanager.login_manual(server, user_found)
except RuntimeError:
window('emby_serverStatus', value="stop")
self._auth = False
@ -246,6 +247,14 @@ class UserClient(threading.Thread):
self._user = None
self.auth = None
current_state = self.connectmanager.get_state()
for server in current_state['Servers']:
if server['Id'] == settings('serverId'):
# Update token
server['AccessToken'] = None
self.connectmanager.update_token(current_state['Servers'], server)
def run(self):
monitor = xbmc.Monitor()