mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-21 03:54:50 +00:00
Better fix for last commit.. AuthManager will now raise a BadLoginError if the username or password
does not match
This commit is contained in:
parent
b6793f7268
commit
2b789b501b
3 changed files with 28 additions and 14 deletions
|
@ -39,6 +39,7 @@ import stat
|
|||
|
||||
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_ADMIN = 10
|
|||
|
||||
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,22 +73,24 @@ class AuthManager(component.Component):
|
|||
|
||||
: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])
|
||||
|
||||
return 0
|
||||
else:
|
||||
raise BadLoginError("Password does not match")
|
||||
|
||||
def __create_localclient_account(self):
|
||||
"""
|
||||
|
|
|
@ -373,6 +373,7 @@ class DaemonSSLProxy(DaemonProxy):
|
|||
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 @@ class DaemonSSLProxy(DaemonProxy):
|
|||
|
||||
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 @@ class DaemonSSLProxy(DaemonProxy):
|
|||
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 @@ class Client(object):
|
|||
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):
|
||||
|
|
|
@ -52,17 +52,22 @@ class Command(BaseCommand):
|
|||
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()
|
||||
|
|
Loading…
Add table
Reference in a new issue