Added an error message when there is an exception in authorisation

This commit is contained in:
Manuel Cortez 2016-06-06 03:53:55 -05:00
parent 4df4e620c1
commit 2b9aa467bd
5 changed files with 25 additions and 9 deletions

View File

@ -98,6 +98,7 @@ class Controller(object):
pub.subscribe(self.view_post, "open-post") pub.subscribe(self.view_post, "open-post")
pub.subscribe(self.update_status_bar, "update-status-bar") pub.subscribe(self.update_status_bar, "update-status-bar")
pub.subscribe(self.chat_from_id, "new-chat") pub.subscribe(self.chat_from_id, "new-chat")
pub.subscribe(self.authorisation_failed, "authorisation-failed")
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit) widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates) widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates)
@ -115,10 +116,14 @@ class Controller(object):
pub.unsubscribe(self.in_post, "posted") pub.unsubscribe(self.in_post, "posted")
pub.unsubscribe(self.download, "download-file") pub.unsubscribe(self.download, "download-file")
pub.unsubscribe(self.play_audio, "play-audio") pub.unsubscribe(self.play_audio, "play-audio")
pub.unsubscribe(self.authorisation_failed, "authorisation-failed")
pub.unsubscribe(self.play_audios, "play-audios") pub.unsubscribe(self.play_audios, "play-audios")
pub.unsubscribe(self.view_post, "open-post") pub.unsubscribe(self.view_post, "open-post")
pub.unsubscribe(self.update_status_bar, "update-status-bar") pub.unsubscribe(self.update_status_bar, "update-status-bar")
def authorisation_failed(self):
commonMessages.bad_authorisation()
def login(self): def login(self):
self.window.change_status(_(u"Logging in VK")) self.window.change_status(_(u"Logging in VK"))
self.session.login() self.session.login()

View File

@ -8,6 +8,8 @@ import logging
import utils import utils
import sound import sound
from config_utils import Configuration, ConfigurationResetException from config_utils import Configuration, ConfigurationResetException
from pubsub import pub
log = logging.getLogger("session") log = logging.getLogger("session")
sessions = {} sessions = {}
@ -222,9 +224,15 @@ class vkSession(object):
self.get_my_data() self.get_my_data()
def authorise(self): def authorise(self):
try:
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"]) self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"])
self.settings["vk"]["token"] = self.vk.client._session.access_token self.settings["vk"]["token"] = self.vk.client._session.access_token
self.settings.write() self.settings.write()
except:
self.settings["vk"]["user"] = ""
self.settings["vk"]["password"] = ""
self.settings.write()
pub.sendMessage("authorisation-failed")
def post_wall_status(self, message, *args, **kwargs): def post_wall_status(self, message, *args, **kwargs):
""" Sends a post to an user, group or community wall.""" """ Sends a post to an user, group or community wall."""

View File

@ -28,6 +28,7 @@ class sessionManagerController(object):
strconfig = "%s/session.conf" % (paths.config_path(i)) strconfig = "%s/session.conf" % (paths.config_path(i))
config_test = Configuration(strconfig) config_test = Configuration(strconfig)
name = config_test["vk"]["user"] name = config_test["vk"]["user"]
if name != "" and config_test["vk"]["password"] != "":
self.session = i self.session = i
s = session.vkSession(self.session) s = session.vkSession(self.session)
s.get_configuration() s.get_configuration()

View File

@ -21,3 +21,6 @@ def show_error_code(code):
title = _(u"Restricted access") title = _(u"Restricted access")
message = _(u"Access to user's audio is denied by the owner. Error code {0}").format(code,) message = _(u"Access to user's audio is denied by the owner. Error code {0}").format(code,)
return wx.MessageDialog(None, message, title, style=wx.ICON_ERROR).ShowModal() return wx.MessageDialog(None, message, title, style=wx.ICON_ERROR).ShowModal()
def bad_authorisation():
return wx.MessageDialog(None, _(u"authorisation failed. Your configuration will not be saved. Please close and open again the application for authorising your account. Make sure you have typed your credentials correctly."), _(u"Error"), style=wx.ICON_ERROR).ShowModal()

View File

@ -38,7 +38,6 @@ class mainWindow(wx.Frame):
self.SetClientSize(self.sizer.CalcMin()) self.SetClientSize(self.sizer.CalcMin())
self.Layout() self.Layout()
self.SetSize(self.GetBestSize()) self.SetSize(self.GetBestSize())
print self.GetSize()
def change_status(self, status): def change_status(self, status):
self.sb.SetStatusText(status) self.sb.SetStatusText(status)