From 17f7e2258493ccb8e599ed2f5b56d246cc788c98 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 8 Oct 2021 10:08:24 -0400 Subject: [PATCH] Island: Add needs_registration() to AuthenticationService --- monkey/monkey_island/cc/resources/auth/registration.py | 4 +--- monkey/monkey_island/cc/services/authentication.py | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/resources/auth/registration.py b/monkey/monkey_island/cc/resources/auth/registration.py index 75cef5018..fd9532456 100644 --- a/monkey/monkey_island/cc/resources/auth/registration.py +++ b/monkey/monkey_island/cc/resources/auth/registration.py @@ -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) diff --git a/monkey/monkey_island/cc/services/authentication.py b/monkey/monkey_island/cc/services/authentication.py index 517b3a50b..fe3542f51 100644 --- a/monkey/monkey_island/cc/services/authentication.py +++ b/monkey/monkey_island/cc/services/authentication.py @@ -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))