From 8151debfe139364266aa764e8c325857c481aa69 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Mon, 19 Oct 2015 20:09:39 -0400 Subject: [PATCH] Can now login to SSO from pyfa, which completes basic integration. This is very crude, will be refined. --- gui/crestFittings.py | 45 +++++++++++++++++++++++++++++++++++++++++++- gui/mainFrame.py | 8 +++++++- gui/mainMenuBar.py | 2 ++ service/crest.py | 10 ++++++++-- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/gui/crestFittings.py b/gui/crestFittings.py index a58ba2e5c..a89ffb925 100644 --- a/gui/crestFittings.py +++ b/gui/crestFittings.py @@ -1,9 +1,16 @@ +import json +import thread + import wx +from wx.lib.pubsub import pub + import service import gui.display as d from eos.types import Cargo from eos.db import getItem -import json +from service.server import * +import config + class CrestFittings(wx.Frame): @@ -129,6 +136,42 @@ class ExportToEve(wx.Frame): except ValueError: self.statusbar.SetStatusText("", 1) +class CrestLogin(wx.Frame): + + def __init__(self, parent): + wx.Frame.__init__(self, parent, id=wx.ID_ANY, title="Login", pos=wx.DefaultPosition, size=wx.Size( -1,-1 ), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) + + self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE)) + + self.mainFrame = parent + sCrest = service.Crest.getInstance() + + mainSizer = wx.BoxSizer( wx.HORIZONTAL ) + self.loginBtn = wx.Button( self, wx.ID_ANY, u"Login via SSO", wx.DefaultPosition, wx.DefaultSize, 5 ) + mainSizer.Add( self.loginBtn, 0, wx.ALL, 5 ) + + self.loginBtn.Bind(wx.EVT_BUTTON, self.startServer) + + self.SetSizer(mainSizer) + self.Layout() + + pub.subscribe(self.sso_login, 'sso_login') + self.Centre(wx.BOTH) + + def sso_login(self, message): + self.httpd.stop() + con = config.pycrest_eve.authorize(message) + sCrest = service.Crest.getInstance() + sCrest.newChar(con) + self.Close() + + def startServer(self, event): + self.httpd = StoppableHTTPServer(('', 6461), AuthHandler) + thread.start_new_thread(self.httpd.serve, ()) + uri = config.pycrest_eve.auth_uri(scopes=['characterFittingsRead', 'characterFittingsWrite']) + wx.LaunchDefaultBrowser(uri) + + class FittingsTreeView(wx.Panel): def __init__(self, parent): wx.Panel.__init__ (self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL) diff --git a/gui/mainFrame.py b/gui/mainFrame.py index 377f2c3f8..499219e37 100644 --- a/gui/mainFrame.py +++ b/gui/mainFrame.py @@ -44,7 +44,7 @@ from gui.multiSwitch import MultiSwitch from gui.statsPane import StatsPane from gui.shipBrowser import ShipBrowser, FitSelected, ImportSelected, Stage3Selected from gui.characterEditor import CharacterEditor, SaveCharacterAs -from gui.crestFittings import CrestFittings, ExportToEve +from gui.crestFittings import CrestFittings, ExportToEve, CrestLogin from gui.characterSelection import CharacterSelection from gui.patternEditor import DmgPatternEditorDlg from gui.resistsEditor import ResistsEditorDlg @@ -420,6 +420,8 @@ class MainFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.eveFittings, id = menuBar.eveFittingsId) # Export to EVE self.Bind(wx.EVT_MENU, self.exportToEve, id = menuBar.exportToEveId) + # Login to EVE + self.Bind(wx.EVT_MENU, self.ssoLogin, id = menuBar.ssoLoginId) #Clipboard exports self.Bind(wx.EVT_MENU, self.exportToClipboard, id=wx.ID_COPY) @@ -488,6 +490,10 @@ class MainFrame(wx.Frame): dlg=CrestFittings(self) dlg.Show() + def ssoLogin(self, event): + dlg=CrestLogin(self) + dlg.Show() + def exportToEve(self, event): dlg=ExportToEve(self) dlg.Show() diff --git a/gui/mainMenuBar.py b/gui/mainMenuBar.py index a54568ee7..1af6e88e5 100644 --- a/gui/mainMenuBar.py +++ b/gui/mainMenuBar.py @@ -43,6 +43,7 @@ class MainMenuBar(wx.MenuBar): self.revertCharId = wx.NewId() self.eveFittingsId = wx.NewId() self.exportToEveId = wx.NewId() + self.ssoLoginId = wx.NewId() self.mainFrame = gui.mainFrame.MainFrame.getInstance() @@ -108,6 +109,7 @@ class MainMenuBar(wx.MenuBar): # CREST Menu crestMenu = wx.Menu() self.Append(crestMenu, "&CREST") + crestMenu.Append(self.ssoLoginId, "Login To EVE") crestMenu.Append(self.eveFittingsId, "Browse EVE Fittings") crestMenu.Append(self.exportToEveId, "Export To EVE") diff --git a/service/crest.py b/service/crest.py index f77829edd..236435a38 100644 --- a/service/crest.py +++ b/service/crest.py @@ -1,4 +1,5 @@ import eos.db +from eos.types import Crest as CrestUser import config class Crest(): @@ -12,7 +13,6 @@ class Crest(): return cls._instance def __init__(self): - pass def getCrestCharacters(self): @@ -29,6 +29,12 @@ class Crest(): def postFitting(self, charID, json): char = self.getCrestCharacter(charID) char.auth() - print char.eve.token res = char.eve._session.post('https://api-sisi.testeveonline.com/characters/%d/fittings/'%char.ID, data=json) return res + + def newChar(self, connection): + connection() + info = connection.whoami() + char = CrestUser(info['CharacterName'], info['CharacterID'], connection.refresh_token) + eos.db.save(char) +