diff options
author | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-03-28 06:22:55 +0100 |
---|---|---|
committer | Jonah BrĂ¼chert <jbb@kaidan.im> | 2024-03-28 16:57:21 +0100 |
commit | a3f0c006b5fb5beab1704aad56777dcd98c42efb (patch) | |
tree | 2a2acb62303c25a299aea4030eff55bca7e28650 /accounts/models.py | |
parent | d5977387f3e6716cc7594dc872539ccd7f130524 (diff) | |
download | web-a3f0c006b5fb5beab1704aad56777dcd98c42efb.tar.gz web-a3f0c006b5fb5beab1704aad56777dcd98c42efb.tar.bz2 web-a3f0c006b5fb5beab1704aad56777dcd98c42efb.zip |
Add some type annotations
Diffstat (limited to 'accounts/models.py')
-rw-r--r-- | accounts/models.py | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/accounts/models.py b/accounts/models.py index 72c061d..fe6c500 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -1,8 +1,27 @@ from flask_login import UserMixin +from typing import Any, Optional + from accounts.utils.login import create_userid +class Service(object): + id: str + name: str + url: str + + def __init__(self, service_id: str, name: str, url: str) -> None: + self.id = service_id + self.name = name + self.url = url + + #: Wether the user has a separate password for this service. + self.changed = False + + def __repr__(self): + return '<Service %s>' % self.id + + class Account(UserMixin): """ An Account represents a complex ldap tree entry for spline users. @@ -10,7 +29,15 @@ class Account(UserMixin): """ _ready = False - def __init__(self, uid, mail, services=None, password=None, uidNumber=None): + uid: str + services: list[str] + password: Optional[str] + new_password_services: dict[str, tuple[Optional[str], Optional[str]]] + attributes: dict[Any, Any] + new_password_root: Optional[tuple[Optional[str], Optional[str]]] + + def __init__(self, uid: str, mail: str, services=None, + password: Optional[str] = None, uidNumber=None): self.uid = uid self.services = list() if services is None else services self.password = password @@ -25,10 +52,11 @@ class Account(UserMixin): def __repr__(self): return "<Account uid=%s>" % self.uid - def reset_password(self, service): + def reset_password(self, service: str): self.new_password_services[service] = (None, None) - def change_password(self, new_password, old_password='', service=None): + def change_password(self, new_password: str, old_password='', + service=None): """ Changes a password for a given service. You have to use the UserBackend to make the changes permanent. If no service is given, @@ -43,7 +71,7 @@ class Account(UserMixin): def _set_attribute(self, key, value): self.attributes[key] = value - def change_email(self, new_mail): + def change_email(self, new_mail: str): """ Changes the mail address of an account. You have to use the AccountService class to make changes permanent. @@ -69,16 +97,3 @@ class Account(UserMixin): the cookie and used to identify the user. """ return create_userid(self.uid, self.password) - - -class Service(object): - def __init__(self, service_id, name, url): - self.id = service_id - self.name = name - self.url = url - - #: Wether the user has a separate password for this service. - self.changed = False - - def __repr__(self): - return '<Service %s>' % self.id |