forked from p15670423/monkey
Refactor get_credentials_from_request to get_username_password_from_request
This better indicates that get_username_password_from_request returns a username/password pair rather than UserCreds structure
This commit is contained in:
parent
da169dddc9
commit
26ba02a1d0
|
@ -10,7 +10,7 @@ from jwt import PyJWTError
|
||||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||||
import monkey_island.cc.resources.auth.user_store as user_store
|
import monkey_island.cc.resources.auth.user_store as user_store
|
||||||
from monkey_island.cc.resources.auth.credential_utils import (
|
from monkey_island.cc.resources.auth.credential_utils import (
|
||||||
get_credentials_from_request,
|
get_username_password_from_request,
|
||||||
password_matches_hash,
|
password_matches_hash,
|
||||||
)
|
)
|
||||||
from monkey_island.cc.server_utils.encryption import (
|
from monkey_island.cc.server_utils.encryption import (
|
||||||
|
@ -44,7 +44,7 @@ class Authenticate(flask_restful.Resource):
|
||||||
"password": "my_password"
|
"password": "my_password"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
username, password = get_credentials_from_request(request)
|
username, password = get_username_password_from_request(request)
|
||||||
|
|
||||||
if _credentials_match_registered_user(username, password):
|
if _credentials_match_registered_user(username, password):
|
||||||
if not get_datastore_encryptor():
|
if not get_datastore_encryptor():
|
||||||
|
|
|
@ -19,13 +19,13 @@ def password_matches_hash(plaintext_password, password_hash):
|
||||||
|
|
||||||
|
|
||||||
def get_user_credentials_from_request(_request) -> UserCreds:
|
def get_user_credentials_from_request(_request) -> UserCreds:
|
||||||
username, password = get_credentials_from_request(_request)
|
username, password = get_username_password_from_request(_request)
|
||||||
password_hash = hash_password(password)
|
password_hash = hash_password(password)
|
||||||
|
|
||||||
return UserCreds(username, password_hash)
|
return UserCreds(username, password_hash)
|
||||||
|
|
||||||
|
|
||||||
def get_credentials_from_request(_request: Request) -> Tuple[str, str]:
|
def get_username_password_from_request(_request: Request) -> Tuple[str, str]:
|
||||||
cred_dict = json.loads(request.data)
|
cred_dict = json.loads(request.data)
|
||||||
username = cred_dict.get("username", "")
|
username = cred_dict.get("username", "")
|
||||||
password = cred_dict.get("password", "")
|
password = cred_dict.get("password", "")
|
||||||
|
|
|
@ -5,7 +5,10 @@ from flask import make_response, request
|
||||||
|
|
||||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||||
from common.utils.exceptions import InvalidRegistrationCredentialsError, RegistrationNotNeededError
|
from common.utils.exceptions import InvalidRegistrationCredentialsError, RegistrationNotNeededError
|
||||||
from monkey_island.cc.resources.auth.credential_utils import get_user_credentials_from_request
|
from monkey_island.cc.resources.auth.credential_utils import (
|
||||||
|
get_user_credentials_from_request,
|
||||||
|
get_username_password_from_request,
|
||||||
|
)
|
||||||
from monkey_island.cc.server_utils.encryption import (
|
from monkey_island.cc.server_utils.encryption import (
|
||||||
initialize_datastore_encryptor,
|
initialize_datastore_encryptor,
|
||||||
remove_old_datastore_key,
|
remove_old_datastore_key,
|
||||||
|
@ -26,7 +29,7 @@ class Registration(flask_restful.Resource):
|
||||||
try:
|
try:
|
||||||
env_singleton.env.try_add_user(credentials)
|
env_singleton.env.try_add_user(credentials)
|
||||||
remove_old_datastore_key()
|
remove_old_datastore_key()
|
||||||
username, password = get_user_credentials_from_request(request)
|
username, password = get_username_password_from_request(request)
|
||||||
initialize_datastore_encryptor(username, password)
|
initialize_datastore_encryptor(username, password)
|
||||||
reset_database()
|
reset_database()
|
||||||
return make_response({"error": ""}, 200)
|
return make_response({"error": ""}, 200)
|
||||||
|
|
Loading…
Reference in New Issue