island: Extract method get_credentials_from_request() from post()

This commit is contained in:
Mike Salvatore 2021-05-04 12:03:33 -04:00
parent 83f7f04929
commit 39c274c4d9
1 changed files with 11 additions and 4 deletions

View File

@ -38,10 +38,8 @@ class Authenticate(flask_restful.Resource):
"password": "my_password"
}
"""
credentials = json.loads(request.data)
# Unpack auth info from request
username = credentials["username"]
password = credentials["password"]
(username, password) = Authenticate._get_credentials_from_request(request)
# If the user and password have been previously registered
if self._authenticate(username, password):
access_token = flask_jwt_extended.create_access_token(
@ -54,6 +52,15 @@ class Authenticate(flask_restful.Resource):
else:
return make_response({"error": "Invalid credentials"}, 401)
@staticmethod
def _get_credentials_from_request(request):
credentials = json.loads(request.data)
username = credentials["username"]
password = credentials["password"]
return (username, password)
@staticmethod
def _authenticate(username, password):
user = user_store.UserStore.username_table.get(username, None)