mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 19:28:09 -06:00
Get back to PIN code authorization due to Twitter changes. Closes #216
This commit is contained in:
parent
c2d81279fe
commit
9847f7ad01
@ -167,19 +167,19 @@ class Session(object):
|
||||
if self.logged == True:
|
||||
raise Exceptions.AlreadyAuthorisedError("The authorisation process is not needed at this time.")
|
||||
else:
|
||||
self.authorisation_thread = call_threaded(self.twitter.authorise, self.settings)
|
||||
self.twitter.authorise()
|
||||
self.authorisation_dialog = authorisationDialog()
|
||||
self.authorisation_dialog.cancel.Bind(wx.EVT_BUTTON, self.authorisation_cancelled)
|
||||
pub.subscribe(self.authorisation_accepted, "authorisation-accepted")
|
||||
self.authorisation_dialog.ok.Bind(wx.EVT_BUTTON, self.authorisation_accepted)
|
||||
self.authorisation_dialog.ShowModal()
|
||||
|
||||
def authorisation_cancelled(self, *args, **kwargs):
|
||||
pub.sendMessage("authorisation-cancelled")
|
||||
self.authorisation_dialog.Destroy()
|
||||
del self.authorisation_dialog
|
||||
|
||||
def authorisation_accepted(self):
|
||||
pub.unsubscribe(self.authorisation_accepted, "authorisation-accepted")
|
||||
def authorisation_accepted(self, *args, **kwargs):
|
||||
pincode = self.authorisation_dialog.text.GetValue()
|
||||
self.twitter.verify_authorisation(self.settings, pincode)
|
||||
self.authorisation_dialog.Destroy()
|
||||
|
||||
def get_more_items(self, update_function, users=False, name=None, *args, **kwargs):
|
||||
|
@ -80,7 +80,9 @@ class authorisationDialog(wx.Dialog):
|
||||
super(authorisationDialog, self).__init__(parent=None, title=_(u"Authorising account..."))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.text = wx.TextCtrl(panel, -1, _("Waiting for account authorisation..."), style=wx.TE_READONLY|wx.TE_MULTILINE)
|
||||
static = wx.StaticText(panel, wx.NewId(), _(u"Enter your PIN code here"))
|
||||
self.text = wx.TextCtrl(panel, -1)
|
||||
self.ok = wx.Button(panel, wx.ID_OK)
|
||||
self.cancel = wx.Button(panel, wx.ID_CANCEL)
|
||||
sizer.Add(self.text, 0, wx.ALL, 5)
|
||||
sizer.Add(self.cancel, 0, wx.ALL, 5)
|
||||
|
@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import config
|
||||
import random
|
||||
import BaseHTTPServer
|
||||
import webbrowser
|
||||
from twython import Twython, TwythonError
|
||||
from keys import keyring
|
||||
import authorisationHandler
|
||||
from requests import certs
|
||||
import logging
|
||||
log = logging.getLogger("sessionTwitter")
|
||||
@ -17,22 +15,17 @@ class twitter(object):
|
||||
if verify_credentials == True:
|
||||
self.credentials = self.twitter.verify_credentials()
|
||||
|
||||
def authorise(self, settings):
|
||||
authorisationHandler.logged = False
|
||||
port = random.randint(30000, 65535)
|
||||
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', port), authorisationHandler.handler)
|
||||
twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), auth_endpoint='authorize')
|
||||
auth = twitter.get_authentication_tokens("http://127.0.0.1:{0}".format(port,))
|
||||
webbrowser.open_new_tab(auth['auth_url'])
|
||||
while authorisationHandler.logged == False:
|
||||
httpd.handle_request()
|
||||
self.twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), auth['oauth_token'], auth['oauth_token_secret'])
|
||||
final = self.twitter.get_authorized_tokens(authorisationHandler.verifier)
|
||||
def authorise(self):
|
||||
twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"))
|
||||
self.auth = twitter.get_authentication_tokens(callback_url="oob")
|
||||
webbrowser.open_new_tab(self.auth['auth_url'])
|
||||
|
||||
def verify_authorisation(self, settings, pincode):
|
||||
self.twitter = Twython(keyring.get("api_key"), keyring.get("api_secret"), self.auth['oauth_token'], self.auth['oauth_token_secret'])
|
||||
final = self.twitter.get_authorized_tokens(pincode)
|
||||
self.save_configuration(settings, final["oauth_token"], final["oauth_token_secret"])
|
||||
httpd.server_close()
|
||||
|
||||
def save_configuration(self, settings, user_key, user_secret):
|
||||
settings["twitter"]["user_key"] = user_key
|
||||
settings["twitter"]["user_secret"] = user_secret
|
||||
settings.write()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user