forked from p15670423/monkey
island: Extract method get_credentials_from_request() from post()
This commit is contained in:
parent
83f7f04929
commit
39c274c4d9
|
@ -38,10 +38,8 @@ class Authenticate(flask_restful.Resource):
|
||||||
"password": "my_password"
|
"password": "my_password"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
credentials = json.loads(request.data)
|
|
||||||
# Unpack auth info from request
|
(username, password) = Authenticate._get_credentials_from_request(request)
|
||||||
username = credentials["username"]
|
|
||||||
password = credentials["password"]
|
|
||||||
# If the user and password have been previously registered
|
# If the user and password have been previously registered
|
||||||
if self._authenticate(username, password):
|
if self._authenticate(username, password):
|
||||||
access_token = flask_jwt_extended.create_access_token(
|
access_token = flask_jwt_extended.create_access_token(
|
||||||
|
@ -54,6 +52,15 @@ class Authenticate(flask_restful.Resource):
|
||||||
else:
|
else:
|
||||||
return make_response({"error": "Invalid credentials"}, 401)
|
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
|
@staticmethod
|
||||||
def _authenticate(username, password):
|
def _authenticate(username, password):
|
||||||
user = user_store.UserStore.username_table.get(username, None)
|
user = user_store.UserStore.username_table.get(username, None)
|
||||||
|
|
Loading…
Reference in New Issue