mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
[Core] Fix bug and add error testing to AuthManager
This commit is contained in:
parent
9319e07db5
commit
93023c5bfc
1 changed files with 5 additions and 1 deletions
|
@ -51,7 +51,7 @@ class Account(object):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return ('<Account username="%(username)s" authlevel=%(authlevel)s>' %
|
return ('<Account username="%(username)s" authlevel=%(authlevel)s>' %
|
||||||
self.__dict__)
|
{"username": self.username, "authlevel": self.authlevel})
|
||||||
|
|
||||||
|
|
||||||
class AuthManager(component.Component):
|
class AuthManager(component.Component):
|
||||||
|
@ -127,6 +127,8 @@ class AuthManager(component.Component):
|
||||||
def create_account(self, username, password, authlevel):
|
def create_account(self, username, password, authlevel):
|
||||||
if username in self.__auth:
|
if username in self.__auth:
|
||||||
raise AuthManagerError("Username in use.", username)
|
raise AuthManagerError("Username in use.", username)
|
||||||
|
if authlevel not in AUTH_LEVELS_MAPPING:
|
||||||
|
raise AuthManagerError("Invalid auth level: '%s'" % authlevel)
|
||||||
try:
|
try:
|
||||||
self.__auth[username] = Account(username, password,
|
self.__auth[username] = Account(username, password,
|
||||||
AUTH_LEVELS_MAPPING[authlevel])
|
AUTH_LEVELS_MAPPING[authlevel])
|
||||||
|
@ -139,6 +141,8 @@ class AuthManager(component.Component):
|
||||||
def update_account(self, username, password, authlevel):
|
def update_account(self, username, password, authlevel):
|
||||||
if username not in self.__auth:
|
if username not in self.__auth:
|
||||||
raise AuthManagerError("Username not known", username)
|
raise AuthManagerError("Username not known", username)
|
||||||
|
if authlevel not in AUTH_LEVELS_MAPPING:
|
||||||
|
raise AuthManagerError("Invalid auth level: '%s'" % authlevel)
|
||||||
try:
|
try:
|
||||||
self.__auth[username].username = username
|
self.__auth[username].username = username
|
||||||
self.__auth[username].password = password
|
self.__auth[username].password = password
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue