Implement a setting for manual vs server login method
This commit is contained in:
@@ -17,6 +17,7 @@ from eos.enum import Enum
|
||||
from eos.saveddata.ssocharacter import SsoCharacter
|
||||
import gui.globalEvents as GE
|
||||
from service.server import StoppableHTTPServer, AuthHandler
|
||||
from service.settings import EsiSettings
|
||||
|
||||
from .esi_security_proxy import EsiSecurityProxy
|
||||
from esipy import EsiClient, EsiApp
|
||||
@@ -39,6 +40,11 @@ class Servers(Enum):
|
||||
SISI = 1
|
||||
|
||||
|
||||
class LoginMethod(Enum):
|
||||
SERVER = 0
|
||||
MANUAL = 1
|
||||
|
||||
|
||||
class Esi(object):
|
||||
esiapp = None
|
||||
esi_v1 = None
|
||||
@@ -75,6 +81,8 @@ class Esi(object):
|
||||
def __init__(self):
|
||||
Esi.initEsiApp()
|
||||
|
||||
self.settings = EsiSettings.getInstance()
|
||||
|
||||
AFTER_TOKEN_REFRESH.add_receiver(self.tokenUpdate)
|
||||
|
||||
# these will be set when needed
|
||||
@@ -119,7 +127,7 @@ class Esi(object):
|
||||
if char is not None and char.esi_client is None:
|
||||
char.esi_client = Esi.genEsiClient()
|
||||
Esi.update_token(char, Esi.get_sso_data(char)) # don't use update_token on security directly, se still need to apply the values here
|
||||
print(repr(char))
|
||||
|
||||
eos.db.commit()
|
||||
return char
|
||||
|
||||
@@ -181,17 +189,33 @@ class Esi(object):
|
||||
char.esi_client.security.update_token(tokenResponse)
|
||||
|
||||
def login(self):
|
||||
# Switch off how we do things here depending on the mode of authentication
|
||||
uri = self.startServer()
|
||||
serverAddr = None
|
||||
if self.settings.get('loginMode') == LoginMethod.SERVER:
|
||||
serverAddr = self.startServer()
|
||||
uri = self.getLoginURI(serverAddr)
|
||||
webbrowser.open(uri)
|
||||
wx.PostEvent(self.mainFrame, GE.SsoLoggingIn())
|
||||
wx.PostEvent(self.mainFrame, GE.SsoLoggingIn(login_mode=self.settings.get('loginMode')))
|
||||
|
||||
def stopServer(self):
|
||||
pyfalog.debug("Stopping Server")
|
||||
self.httpd.stop()
|
||||
self.httpd = None
|
||||
|
||||
def startServer(self):
|
||||
def getLoginURI(self, redirect=None):
|
||||
self.state = str(uuid.uuid4())
|
||||
esisecurity = EsiSecurityProxy(sso_url=config.ESI_AUTH_PROXY)
|
||||
|
||||
args = {
|
||||
'state': self.state,
|
||||
'pyfa_version': config.version,
|
||||
}
|
||||
|
||||
if redirect is not None:
|
||||
args['redirect'] = redirect
|
||||
|
||||
return esisecurity.get_auth_uri(**args)
|
||||
|
||||
def startServer(self): # todo: break this out into two functions: starting the server, and getting the URI
|
||||
pyfalog.debug("Starting server")
|
||||
|
||||
# we need this to ensure that the previous get_request finishes, and then the socket will close
|
||||
@@ -199,20 +223,14 @@ class Esi(object):
|
||||
self.stopServer()
|
||||
time.sleep(1)
|
||||
|
||||
self.state = str(uuid.uuid4())
|
||||
self.httpd = StoppableHTTPServer(('localhost', 0), AuthHandler)
|
||||
port = self.httpd.socket.getsockname()[1]
|
||||
|
||||
esisecurity = EsiSecurityProxy(sso_url=config.ESI_AUTH_PROXY)
|
||||
|
||||
uri = esisecurity.get_auth_uri(state=self.state, redirect='http://localhost:{}'.format(port), pyfa_version=config.version)
|
||||
|
||||
self.serverThread = threading.Thread(target=self.httpd.serve, args=(self.handleServerLogin,))
|
||||
self.serverThread.name = "SsoCallbackServer"
|
||||
self.serverThread.daemon = True
|
||||
self.serverThread.start()
|
||||
|
||||
return uri
|
||||
return 'http://localhost:{}'.format(port)
|
||||
|
||||
def handleLogin(self, ssoInfo):
|
||||
auth_response = json.loads(base64.b64decode(ssoInfo))
|
||||
|
||||
@@ -352,32 +352,32 @@ class UpdateSettings(object):
|
||||
self.serviceUpdateSettings[type] = value
|
||||
|
||||
|
||||
class CRESTSettings(object):
|
||||
class EsiSettings(object):
|
||||
_instance = None
|
||||
|
||||
@classmethod
|
||||
def getInstance(cls):
|
||||
if cls._instance is None:
|
||||
cls._instance = CRESTSettings()
|
||||
cls._instance = EsiSettings()
|
||||
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
# mode
|
||||
# 0 - Implicit authentication
|
||||
# 1 - User-supplied client details
|
||||
serviceCRESTDefaultSettings = {"mode": 0, "server": 0, "clientID": "", "clientSecret": "", "timeout": 60}
|
||||
# LoginMode:
|
||||
# 0 - Server Start Up
|
||||
# 1 - User copy and paste data from website to pyfa
|
||||
defaults = {"loginMode": 0, "clientID": "", "clientSecret": "", "timeout": 60}
|
||||
|
||||
self.serviceCRESTSettings = SettingsProvider.getInstance().getSettings(
|
||||
"pyfaServiceCRESTSettings",
|
||||
serviceCRESTDefaultSettings
|
||||
self.settings = SettingsProvider.getInstance().getSettings(
|
||||
"pyfaServiceEsiSettings",
|
||||
defaults
|
||||
)
|
||||
|
||||
def get(self, type):
|
||||
return self.serviceCRESTSettings[type]
|
||||
return self.settings[type]
|
||||
|
||||
def set(self, type, value):
|
||||
self.serviceCRESTSettings[type] = value
|
||||
self.settings[type] = value
|
||||
|
||||
|
||||
class StatViewSettings(object):
|
||||
|
||||
Reference in New Issue
Block a user