Skip to content

Commit

Permalink
Simplify the pre-processor used to check if a user is authenticated.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Feb 3, 2020
1 parent 19eff8f commit 9c78e4c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions mosp/web/views/api/v1/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ def auth_func(*args, **kw):
"""
Pre-processor used to check if a user is authenticated.
"""
if current_user.is_authenticated:
return

user = None
if request.headers.get('Authorization', False):
token = request.headers.get('Authorization').split(' ')[1]
user = User.query.filter(User.apikey == token).first()

if request.authorization:
user = User.query.filter(User.login == request.authorization.username).first()
if not user:
raise ProcessingException("Couldn't authenticate your user", code=401)
if not user.check_password(request.authorization.password):
raise ProcessingException("Couldn't authenticate your user", code=401)
if not user.is_active:
raise ProcessingException("Couldn't authenticate your user", code=401)
if not user.is_api:
if user and not user.check_password(request.authorization.password):
raise ProcessingException("Couldn't authenticate your user", code=401)
login_user_bundle(user)

if not current_user.is_authenticated:
raise ProcessingException(description="Not authenticated!", code=401)
if not user:
raise ProcessingException("Couldn't authenticate your user", code=401)
if not user.is_active:
raise ProcessingException("Couldn't authenticate your user", code=401)

login_user_bundle(user)


def check_single_object_edit_permission(instance_id, data):
Expand Down

0 comments on commit 9c78e4c

Please sign in to comment.