refactor: User.has_password factorization

This commit is contained in:
Éloi Rivard 2024-04-07 18:33:43 +02:00
parent e317780e1d
commit e339d1169d
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
5 changed files with 1 additions and 13 deletions

View file

@ -65,9 +65,6 @@ class User(canaille.core.models.User, LDAPObject):
def identifier(self):
return self.rdn_value
def has_password(self):
return bool(self.password)
def check_password(self, password):
conn = ldap.initialize(current_app.config["CANAILLE_LDAP"]["URI"])

View file

@ -250,9 +250,6 @@ class User(canaille.core.models.User, MemoryModel):
def get_from_login(cls, login=None, **kwargs):
return User.get(user_name=login)
def has_password(self):
return bool(self.password)
def check_password(self, password):
if password != self.password:
return (False, None)

View file

@ -175,9 +175,6 @@ class User(canaille.core.models.User, Base, SqlAlchemyModel):
def get_from_login(cls, login=None, **kwargs):
return User.get(user_name=login)
def has_password(self):
return self.password is not None
def check_password(self, password):
if password != self.password:
return (False, None)

View file

@ -250,7 +250,7 @@ class User(Model):
def has_password(self) -> bool:
"""Checks wether a password has been set for the user."""
raise NotImplementedError()
return self.password is not None
def check_password(self, password: str) -> bool:
"""Checks if the password matches the user password in the database."""

View file

@ -11,9 +11,6 @@ def test_required_methods(testclient):
user = User()
with pytest.raises(NotImplementedError):
user.has_password()
with pytest.raises(NotImplementedError):
user.check_password("password")