1
# Copyright (C) 2010 Canonical
6
# This program is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation; version 3.
10
# This program is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
gobject.threads_init()
27
from gettext import gettext as _
30
from softwarecenter.backend.launchpad import GLaunchpad
31
from softwarecenter.backend.restfulclient import UbuntuSSOlogin
34
class LoginDialog(object):
36
def __init__(self, loginbackend, datadir, parent=None):
38
self.loginbackend = loginbackend
39
self.loginbackend.connect("need-username-password",
40
self.cb_need_username_password)
41
self.loginbackend.connect("login-successful", self.cb_login_successful)
42
self.loginbackend.connect("login-failed", self.cb_login_failure)
45
self.builder = gtk.Builder()
46
self.builder.add_from_file(datadir+"/ui/login.ui")
47
self.builder.connect_signals(self)
48
for o in self.builder.get_objects():
49
if issubclass(type(o), gtk.Buildable):
50
name = gtk.Buildable.get_name(o)
51
setattr(self, name, o)
53
print >> sys.stderr, "WARNING: can not get name for '%s'" % o
56
self.dialog_login.set_transient_for(parent)
60
#self.login_spinner = gtk.Spinner()
61
#self.dialog_action_area_login.pack_start(self.login_spinner)
62
#self.dialog_action_area_login.reorder_child(self.login_spinner, 0)
63
#self.login_spinner.start()
64
#self.login_spinner.show()
67
self.loginbackend.login()
69
def cb_need_username_password(self, lp):
70
res = self.dialog_login.run()
71
self.dialog_login.hide()
72
if res != gtk.RESPONSE_OK:
73
self.on_button_cancel_clicked()
75
self._enter_user_name_password_finished()
77
def cb_login_successful(self, lp, token):
78
""" callback when the login was successful """
79
print "login_successful", token
81
def cb_login_failure(self, lp):
82
""" callback when the login failed """
83
softwarecenter.view.dialogs.error(self.parent,
84
_("Authentication failure"),
85
_("Sorry, please try again"))
86
self.cb_need_username_password(None)
88
def on_button_cancel_clicked(self, button=None):
89
self.loginbackend.cancel_login()
90
self.dialog_login.hide()
91
while gtk.events_pending():
94
def _enter_user_name_password_finished(self):
95
""" run when the user finished with the login dialog box
96
this checks the users choices and sets the appropriate state
98
has_account = self.radiobutton_review_login_have_account.get_active()
99
new_account = self.radiobutton_review_login_register_new_account.get_active()
100
forgotten_pw = self.radiobutton_review_login_forgot_password.get_active()
102
username = self.entry_review_login_email.get_text()
103
password = self.entry_review_login_password.get_text()
104
self.loginbackend.login(username, password)
107
subprocess.call(["xdg-open", self.loginbackend.new_account_url])
109
#print "forgotten passowrd"
110
subprocess.call(["xdg-open", self.loginbackend.forgot_password_url])
114
if __name__ == "__main__":
116
logging.basicConfig(level=logging.DEBUG)
118
if sys.argv[1] == "launchpad":
119
loginbackend = GLaunchpad()
120
elif sys.argv[1] == "sso":
121
loginbackend = UbuntuSSOlogin()
123
print "need either 'sso' or 'launchpad' as arguments"
124
d = LoginDialog(loginbackend, datadir="./data")
129
except KeyboardInterrupt:
130
# FIXME: port shutdown?!?
131
#glaunchpad.shutdown()