TASK-002 Enforce authorization and media boundaries
This commit is contained in:
@@ -16,10 +16,11 @@ basic_auth.realm = "Incorrect Credentials"
|
||||
def get_token():
|
||||
"""Get token."""
|
||||
user = basic_auth.current_user()
|
||||
user.get_token()
|
||||
refresh_token = user.get_refresh_token()
|
||||
db.session.commit()
|
||||
response = make_response(
|
||||
jsonify(user.to_dict(rules=("is_admin", "token")))
|
||||
jsonify({**user.to_dict(rules=("is_admin", "token")), "user_id": user.id})
|
||||
)
|
||||
response.set_cookie("refresh_token", value=refresh_token, httponly=True)
|
||||
return response
|
||||
@@ -41,10 +42,12 @@ def refresh_token():
|
||||
if refresh_token is None:
|
||||
return error_response(400, "Bad request, no refresh token")
|
||||
user = User.query.filter_by(refresh_token=refresh_token).first()
|
||||
if user is not None:
|
||||
if user is not None and user.login_disabled is False:
|
||||
access_token = user.get_token()
|
||||
db.session.commit()
|
||||
return {
|
||||
"token": access_token,
|
||||
"user_id": user.id,
|
||||
}
|
||||
|
||||
return error_response(401)
|
||||
|
||||
Reference in New Issue
Block a user