Island: Add needs_registration() to AuthenticationService

This commit is contained in:
Mike Salvatore 2021-10-08 10:08:24 -04:00
parent 252c1d940a
commit 17f7e22584
2 changed files with 5 additions and 3 deletions

View File

@ -3,7 +3,6 @@ import logging
import flask_restful
from flask import make_response, request
import monkey_island.cc.environment.environment_singleton as env_singleton
from common.utils.exceptions import InvalidRegistrationCredentialsError, RegistrationNotNeededError
from monkey_island.cc.resources.auth.credential_utils import get_username_password_from_request
from monkey_island.cc.services.authentication import AuthenticationService
@ -13,8 +12,7 @@ logger = logging.getLogger(__name__)
class Registration(flask_restful.Resource):
def get(self):
is_registration_needed = env_singleton.env.needs_registration()
return {"needs_registration": is_registration_needed}
return {"needs_registration": AuthenticationService.needs_registration()}
def post(self):
username, password = get_username_password_from_request(request)

View File

@ -19,6 +19,10 @@ class AuthenticationService:
def initialize(cls, key_file_directory):
cls.KEY_FILE_DIRECTORY = key_file_directory
@classmethod
def needs_registration(cls) -> bool:
return env_singleton.env.needs_registration()
@classmethod
def register_new_user(cls, username: str, password: str):
credentials = UserCreds(username, _hash_password(password))