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.

This commit is contained in:
Pedro Algarvio 2010-12-21 17:45:45 +00:00
parent b3870ad6dd
commit 86a1b801f5
4 changed files with 57 additions and 39 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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(_("<b>Username:</b>"))
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(_("<b>Password:</b>"))
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()