~ubuntu-branches/ubuntu/precise/software-center/precise

« back to all changes in this revision

Viewing changes to softwarecenter/backend/piston/sso_helper.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Gary Lasker
  • Date: 2012-03-30 18:00:50 UTC
  • Revision ID: package-import@ubuntu.com-20120330180050-vuoqiczj131r9tgh
Tags: 5.1.14
[ Michael Vogt ]
* lp:~mvo/software-center/lp962580:
  - add locking to the expunge helper process to fix bugs that are triggered
    if multiple expunge cache processes are run (LP: #962580)
* lp:~mvo/software-center/cache-refresh-glitch:
  - ensure that we get a full refresh if a pkg was not available before
    show_app is called
* lp:~mvo/software-center/lp940482:
  - fix crash if the debfile does not return proper utf8 for the
    description (LP: #940482)
* lp:~mvo/software-center/lp966514:
  - properly handle network disconnect conditions with the Ubuntu
    SSO dialog (LP: #966514)
* lp:~mvo/software-center/lp966879:
  - fix for crashes in the installed view treeview (LP: #966879,
    LP: #950899)
* lp:~mvo/software-center/lp846204:
  - fix ValueError crashes in get_iter due to invalid tree paths
    (LP: #846204)
* lp:~mvo/software-center/lp964433:
  - disconnect the model from the view before calling set_from_matches
    (LP: #964433)
* lp:~mvo/software-center/treeview-keep-state-on-db-cache-change:
 - restore the state of the installed view treeview when the
   the db or cache changes, such as on an app install or remove
* lp:~mvo/software-center/946393:
 - fix installing multiple apps when in a custom list view (LP: #946393)
* lp:~mvo/software-center/lp969050:
 - disconnect the view when the model is cleared to avoid a furry of
   cursor_changed signals as the rows get removed (LP: #969050)

[ Gary Lasker ]
* lp:~gary-lasker/software-center/installed-pane-refresh:
  - avoid rebuilding the treeview in the installedpane if its not
    required (LP: #828887)
* lp:~gary-lasker/software-center/fix-crash-lp967036:
  - Small branch to fix a crash due to a UnicodeDecodeError when accessing 
    the short description for H/W requirements (LP: #967036)
* lp:~gary-lasker/software-center/fix-crash-lp935930:
  - fix a crash due to a UnicodeDecodeError (LP: #935930)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# Copyright (C) 2012 Canonical
3
 
#
4
 
# Authors:
5
 
#  Michael Vogt
6
 
#
7
 
# This program is free software; you can redistribute it and/or modify it under
8
 
# the terms of the GNU General Public License as published by the Free Software
9
 
# Foundation; version 3.
10
 
#
11
 
# This program is distributed in the hope that it will be useful, but WITHOUT
12
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14
 
# details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License along with
17
 
# this program; if not, write to the Free Software Foundation, Inc.,
18
 
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 
 
20
 
from gi.repository import GObject
21
 
from gettext import gettext as _
22
 
 
23
 
from softwarecenter.backend.login_sso import get_sso_backend
24
 
from softwarecenter.backend.ubuntusso import UbuntuSSOAPI
25
 
from softwarecenter.enums import (SOFTWARE_CENTER_NAME_KEYRING,
26
 
                                  SOFTWARE_CENTER_SSO_DESCRIPTION,
27
 
                                  )
28
 
from softwarecenter.utils import clear_token_from_ubuntu_sso
29
 
 
30
 
 
31
 
class SSOLoginHelper(object):
32
 
    def __init__(self, xid=0):
33
 
        self.oauth = None
34
 
        self.xid = xid
35
 
        self.loop = GObject.MainLoop(GObject.main_context_default())
36
 
 
37
 
    def _login_successful(self, sso_backend, oauth_result):
38
 
        self.oauth = oauth_result
39
 
        # FIXME: actually verify the token against ubuntu SSO
40
 
        self.loop.quit()
41
 
 
42
 
    def verify_token(self, token):
43
 
        def _whoami_done(sso, me):
44
 
            self._whoami = me
45
 
            self.loop.quit()
46
 
 
47
 
        def _whoami_error(sso, err):
48
 
            #print "ERRR", err
49
 
            self.loop.quit()
50
 
        self._whoami = None
51
 
        sso = UbuntuSSOAPI()
52
 
        sso.connect("whoami", _whoami_done)
53
 
        sso.connect("error", _whoami_error)
54
 
        sso.whoami()
55
 
        self.loop.run()
56
 
        # check if the token is valid
57
 
        if self._whoami is None:
58
 
            return False
59
 
        else:
60
 
            return True
61
 
 
62
 
    def clear_token(self):
63
 
        clear_token_from_ubuntu_sso(SOFTWARE_CENTER_NAME_KEYRING)
64
 
 
65
 
    def get_oauth_token_and_verify_sync(self):
66
 
        token = self.get_oauth_token_sync()
67
 
        # check if the token is valid and reset it if it is not
68
 
        if token and not self.verify_token(token):
69
 
            self.clear_token()
70
 
            # re-trigger login
71
 
            token = self.get_oauth_token_sync()
72
 
        return token
73
 
 
74
 
    def get_oauth_token_sync(self):
75
 
        self.oauth = None
76
 
        sso = get_sso_backend(
77
 
            self.xid,
78
 
            SOFTWARE_CENTER_NAME_KEYRING,
79
 
            _(SOFTWARE_CENTER_SSO_DESCRIPTION))
80
 
        sso.connect("login-successful", self._login_successful)
81
 
        sso.connect("login-failed", lambda s: self.loop.quit())
82
 
        sso.connect("login-canceled", lambda s: self.loop.quit())
83
 
        sso.login_or_register()
84
 
        self.loop.run()
85
 
        return self.oauth