Author: andar
Revision: 5469
Log:
Better fix for last commit.. AuthManager will now raise a
BadLoginError if the username or password
does not match
Diff:
Modified: trunk/deluge/core/authmanager.py
===================================================================
--- trunk/deluge/core/authmanager.py 2009-07-06 20:00:41 UTC (rev 5468)
+++ trunk/deluge/core/authmanager.py 2009-07-06 21:09:22 UTC (rev 5469)
@@ -39,6 +39,7 @@
import deluge.component as component
import deluge.configmanager as configmanager
+import deluge.error
from deluge.log import LOG as log
@@ -49,6 +50,9 @@
AUTH_LEVEL_DEFAULT = AUTH_LEVEL_NORMAL
+class BadLoginError(deluge.error.DelugeError):
+ pass
+
class AuthManager(component.Component):
def __init__(self):
component.Component.__init__(self, "AuthManager")
@@ -69,23 +73,25 @@
:param username: str, username
:param password: str, password
- :returns: int, the auth level for this user or 0 if not able to
authenticate
+ :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:
- return 0
+ raise BadLoginError("Username does not exist")
if self.__auth[username][0] == password:
# Return the users auth level
return int(self.__auth[username][1])
+ else:
+ raise BadLoginError("Password does not match")
- return 0
-
def __create_localclient_account(self):
"""
Returns the string.
Modified: trunk/deluge/ui/client.py
===================================================================
--- trunk/deluge/ui/client.py 2009-07-06 20:00:41 UTC (rev 5468)
+++ trunk/deluge/ui/client.py 2009-07-06 21:09:22 UTC (rev 5469)
@@ -373,6 +373,7 @@
msg += "\n" + error.traceback + "\n" + error.exception_type + ": " +
error.exception_msg
msg += "\n" + "-" * 80
log.error(msg)
+ return error_data
def __on_connect(self, result, username, password):
self.__login_deferred = self.call("daemon.login", username, password)
@@ -381,14 +382,9 @@
def __on_connect_fail(self, reason):
log.debug("connect_fail: %s", reason)
- self.login_deferred.callback(False)
+ self.login_deferred.errback(reason)
def __on_login(self, result, username):
- if not result:
- # We received a 0 auth level from the server which means it failed
- self.login_deferred.errback(result)
- return
-
self.username = username
# We need to tell the daemon what events we're interested in receiving
if self.__factory.event_handlers:
@@ -396,7 +392,8 @@
self.login_deferred.callback(result)
def __on_login_fail(self, result):
- self.login_deferred.callback(False)
+ log.debug("_on_login_fail(): %s", result)
+ self.login_deferred.errback(result)
def set_disconnect_callback(self, cb):
"""
@@ -518,6 +515,12 @@
self._daemon_proxy = DaemonSSLProxy(dict(self.__event_handlers))
self._daemon_proxy.set_disconnect_callback(self.__on_disconnect)
d = self._daemon_proxy.connect(host, port, username, password)
+ def on_connect_fail(result):
+ log.debug("on_connect_fail: %s", result)
+ self.disconnect()
+ return result
+
+ d.addErrback(on_connect_fail)
return d
def disconnect(self):
Modified: trunk/deluge/ui/console/commands/connect.py
===================================================================
--- trunk/deluge/ui/console/commands/connect.py 2009-07-06 20:00:41 UTC (rev
5468)
+++ trunk/deluge/ui/console/commands/connect.py 2009-07-06 21:09:22 UTC (rev
5469)
@@ -52,17 +52,22 @@
else:
port = int(port)
- def on_disconnect(result):
+ def do_connect():
d = client.connect(host, port, username, password)
def on_connect(result):
self.console.write("{!success!}Connected to %s:%s!" % (host,
port))
component.start()
def on_connect_fail(result):
- self.console.write("{!error!}Failed to connect to %s:%s!" %
(host, port))
+ self.console.write("{!error!}Failed to connect to %s:%s with
reason: %s" % (host, port, result.value.exception_msg))
d.addCallback(on_connect)
d.addErrback(on_connect_fail)
return d
- client.disconnect().addCallback(on_disconnect)
+ if client.connected():
+ def on_disconnect(result):
+ do_connect()
+ client.disconnect().addCallback(on_disconnect)
+ else:
+ do_connect()
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---