Module: deluge
Branch: multiuser
Commit: 6c6ed486a847a8bceea339e44baee5752fd8aa7c

Author: Pedro Algarvio <[email protected]>
Date:   Tue Dec 21 17:45:45 2010 +0000

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           |   29 ++++++++------------------
 deluge/ui/client.py                  |   10 ++++----
 deluge/ui/gtkui/connectionmanager.py |   17 ++++++++-------
 deluge/ui/gtkui/dialogs.py           |   36 ++++++++++++++++++++++++++++++---
 4 files changed, 55 insertions(+), 37 deletions(-)

diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py
index 0362210..2c147f8 100644
--- a/deluge/core/authmanager.py
+++ b/deluge/core/authmanager.py
@@ -64,42 +64,31 @@ class AuthManager(component.Component):
     def shutdown(self):
         pass
 
-    def peek(self, username):
+    def authorize(self, username, password):
         """
-        Peeks users based on username and returns their auth level
+        Authorizes users based on username and password
 
         :param username: str, username
+        :param password: str, password
         :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:
+        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")
 
-        return int(self.__auth[username][1])
-
-
-    def authorize(self, username, password):
-        """
-        Authorizes users based on username and password
-
-        :param username: str, username
-        :param password: str, password
-        :returns: int, the auth level for this user
-        :rtype: int
-
-        :raises BadLoginError: if the username does not exist or password does 
not match
-
-        """
-        auth_level = self.peek(username)
         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 50a6e91..b433dc0 100644
--- a/deluge/ui/client.py
+++ b/deluge/ui/client.py
@@ -573,11 +573,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 325fb98..db3f1b7 100644
--- a/deluge/ui/gtkui/connectionmanager.py
+++ b/deluge/ui/gtkui/connectionmanager.py
@@ -330,7 +330,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)
 
@@ -443,10 +443,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
@@ -469,11 +468,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"),
@@ -519,7 +520,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 b936c17..d0e8f79 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(_("<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()

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to