diff options
Diffstat (limited to 'accounts/backend/user/dummy.py')
-rw-r--r-- | accounts/backend/user/dummy.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/accounts/backend/user/dummy.py b/accounts/backend/user/dummy.py index 8c54dac..3d0dcca 100644 --- a/accounts/backend/user/dummy.py +++ b/accounts/backend/user/dummy.py @@ -2,9 +2,13 @@ from fnmatch import fnmatch from . import Backend from accounts.models import Account +from accounts import AccountsFlask +from typing import Optional -def _match_filter(account, filters, wildcard): + +def _match_filter(account: Account, filters: Optional[dict[str, str]], + wildcard: bool): if filters is None: return True @@ -30,7 +34,7 @@ class DummyBackend(Backend): users (test and test2) are created. """ - def __init__(self, app): + def __init__(self, app: AccountsFlask) -> None: super(DummyBackend, self).__init__(app) self._storage = { @@ -65,7 +69,7 @@ class DummyBackend(Backend): ) return accounts - def auth(self, username, password): + def auth(self, username: str, password: str): """ Tries to authenticate a user with a given password. If the authentication is successful an Account object will be returned. @@ -76,30 +80,31 @@ class DummyBackend(Backend): acc.password = password return acc - def find(self, filters=None, wildcard=False): + def find(self, filters: Optional[dict[str, str]] = None, + wildcard=False) -> list[Account]: """ Find accounts by a given filter. """ return [acc for acc in self._get_accounts() if _match_filter(acc, filters, wildcard)] - def _store(self, account): + def _store(self, account: Account) -> None: self._storage[account.uid] = { "uidNumber": account.uidNumber, "mail": account.mail, "password": account.password } - def _verify_password(self, account, password): + def _verify_password(self, account: Account, password: Optional[str]): return password == self._storage[account.uid]["password"] - def _alter_password(self, account, password): + def _alter_password(self, account: Account, password: Optional[str]): self._storage[account.uid]["password"] = password - def update(self, account, as_admin=False): + def update(self, account: Account, as_admin=False): """ Updates account information like passwords or email. """ - stored_account = self.get_by_uid(account.uid) + stored_account: Account = self.get_by_uid(account.uid) if not as_admin: if not self._verify_password(stored_account, account.password): raise self.InvalidPasswordError("Invalid password") @@ -109,16 +114,16 @@ class DummyBackend(Backend): if self._verify_password(stored_account, old): self._alter_password(stored_account, new) - def delete(self, account, as_admin=False): + def delete(self, account: Account, as_admin=False): """ Deletes an account permanently. """ - stored_account = self.get_by_uid(account.uid) + stored_account: Account = self.get_by_uid(account.uid) if not as_admin: if stored_account.password != account.password: raise self.InvalidPasswordError("Invalid password") - self._storage = [acc for acc in self._storage if acc.uid != account.uid] + self._storage.pop(stored_account.uid) def _get_next_uidNumber(self): value = self._next_uidNumber |