From 86a1b801f572a7a5f1f66ee16f343a8c4ab76d9f Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 21 Dec 2010 17:45:45 +0000 Subject: [PATCH] Now it is possible to not even store the username on the hosts entry in the connection manager, both username and password will be asked to the user. WARNING: No more "localclient" automatic login, ie, username, is mandatory else, it will be asked to the user. --- deluge/core/authmanager.py | 33 +++++++++---------------- deluge/ui/client.py | 10 ++++---- deluge/ui/gtkui/connectionmanager.py | 17 ++++++------- deluge/ui/gtkui/dialogs.py | 36 ++++++++++++++++++++++++---- 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index 8ad62b34f..955421814 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -65,26 +65,6 @@ class AuthManager(component.Component): def shutdown(self): pass - def peek(self, username): - """ - Peeks users based on username and returns their auth level - - :param username: str, username - :returns: int, the auth level for this user - :rtype: int - - :raises BadLoginError: if the username does not exist or password does not match - - """ - if username not in self.__auth: - # Let's try to re-load the file.. Maybe it's been updated - self.__load_auth_file() - if username not in self.__auth: - raise BadLoginError("Username does not exist") - - return int(self.__auth[username][1]) - - def authorize(self, username, password): """ Authorizes users based on username and password @@ -97,10 +77,19 @@ class AuthManager(component.Component): :raises BadLoginError: if the username does not exist or password does not match """ - auth_level = self.peek(username) + if not username: + raise AuthenticationRequired("Username and Password are required.", + username) + + if username and username not in self.__auth: + # Let's try to re-load the file.. Maybe it's been updated + self.__load_auth_file() + if username not in self.__auth: + raise BadLoginError("Username does not exist") + if self.__auth[username][0] == password: # Return the users auth level - return auth_level + return int(self.__auth[username][1]) elif not password and self.__auth[username][0]: raise AuthenticationRequired("Password is required", username) else: diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 60e51dbf0..4fc8817ec 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -575,11 +575,11 @@ class Client(object): has been established or fails """ log.debug("real client connect") - if not username and host in ("127.0.0.1", "localhost"): - # No username was provided and it's the localhost, so we can try - # to grab the credentials from the auth file. - import common - username, password = common.get_localhost_auth() +# if not username and host in ("127.0.0.1", "localhost"): +# # No username was provided and it's the localhost, so we can try +# # to grab the credentials from the auth file. +# import common +# username, password = common.get_localhost_auth() self._daemon_proxy = DaemonSSLProxy(dict(self.__event_handlers)) self._daemon_proxy.set_disconnect_callback(self.__on_disconnect) diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index 7af987bd9..7cf38f643 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -332,7 +332,7 @@ class ConnectionManager(component.Component): # Create a new Client instance c = deluge.ui.client.Client() - d = c.connect(host, port) + d = c.connect(host, port, skip_authentication=True) d.addCallback(on_connect, c, host_id) d.addErrback(on_connect_failed, host_id) @@ -445,10 +445,9 @@ that you forgot to install the deluged package or it's not in your PATH.")).run( details=traceback.format_exc(tb[2])).run() # Signal handlers - def __connect(self, host_id, host, port, username, password): + def __connect(self, host_id, host, port, username, password, skip_authentication=False): def do_connect(*args): - d = client.connect(host, port, username, password, - skip_authentication=False) + d = client.connect(host, port, username, password, skip_authentication) d.addCallback(self.__on_connected, host_id) d.addErrback(self.__on_connected_failed, host_id, host, port, username) return d @@ -471,11 +470,13 @@ that you forgot to install the deluged package or it's not in your PATH.")).run( # log.debug(reason.value.__dict__) if reason.check(AuthenticationRequired): log.debug("PasswordRequired exception") - dialog = dialogs.AuthenticationDialog(reason.value.message) + dialog = dialogs.AuthenticationDialog(reason.value.message, + reason.value.username) def dialog_finished(response_id, host, port, user): if response_id == gtk.RESPONSE_OK: - self.__connect(host_id, host, port, user, - dialog.password.get_text()) + self.__connect(host_id, host, port, + user and user or dialog.get_username(), + dialog.get_password()) d = dialog.run().addCallback(dialog_finished, host, port, user) return d dialogs.ErrorDialog(_("Failed To Authenticate"), @@ -521,7 +522,7 @@ that you forgot to install the deluged package or it's not in your PATH.")).run( do_retry_connect(6) - return self.__connect(host_id, host, port, user, password) + return self.__connect(host_id, host, port, user, password, skip_authentication=False) def on_button_close_clicked(self, widget): self.connection_manager.response(gtk.RESPONSE_CLOSE) diff --git a/deluge/ui/gtkui/dialogs.py b/deluge/ui/gtkui/dialogs.py index b936c17a7..d0e8f7913 100644 --- a/deluge/ui/gtkui/dialogs.py +++ b/deluge/ui/gtkui/dialogs.py @@ -208,8 +208,36 @@ class AuthenticationDialog(BaseDialog): (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_CONNECT, gtk.RESPONSE_OK), parent) - self.password = gtk.Entry() - self.password.set_visibility(False) - self.vbox.pack_start(self.password, False, False) - self.set_focus(self.password) + table = gtk.Table(2, 2, False) + self.username_label = gtk.Label() + self.username_label.set_markup(_("Username:")) + self.username_label.set_alignment(1.0, 0.5) + self.username_label.set_padding(5, 5) + self.username_entry = gtk.Entry() + table.attach(self.username_label, 0, 1, 0, 1) + table.attach(self.username_entry, 1, 2, 0, 1) + + self.password_label = gtk.Label() + self.password_label.set_markup(_("Password:")) + self.password_label.set_alignment(1.0, 0.5) + self.password_label.set_padding(5, 5) + self.password_entry = gtk.Entry() + self.password_entry.set_visibility(False) + table.attach(self.password_label, 0, 1, 1, 2) + table.attach(self.password_entry, 1, 2, 1, 2) + + self.vbox.pack_start(table, False, False, padding=5) + self.set_focus(self.password_entry) + if username: + self.username_entry.set_text(username) + self.username_entry.set_editable(False) + self.set_focus(self.password_entry) + else: + self.set_focus(self.username_entry) self.show_all() + + def get_username(self): + return self.username_entry.get_text() + + def get_password(self): + return self.password_entry.get_text()