Island: Add docstrings to AuthenticationService

This commit is contained in:
Shreya Malviya 2022-08-02 14:36:39 +05:30
parent 4801235c4b
commit 677e2755b9
1 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,10 @@ from monkey_island.cc.setup.mongo.database_initializer import reset_database
class AuthenticationService:
"""
A service for user authentication
"""
def __init__(
self,
data_dir: Path,
@ -29,9 +33,21 @@ class AuthenticationService:
self._repository_encryptor = repository_encryptor
def needs_registration(self) -> bool:
"""
Checks if a user is already registered on the Island
:return: Whether registration is required on the Island
"""
return not self._user_repository.has_registered_users()
def register_new_user(self, username: str, password: str):
"""
Registers a new user on the Island, then resets the encryptor and database
:param username: Username to register
:param password: Password to register
:raises InvalidRegistrationCredentialsError: If username or password is empty
"""
if not username or not password:
raise InvalidRegistrationCredentialsError("Username or password can not be empty.")