Skip to content

Commit

Permalink
user authentication refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
freelancing-solutions committed Sep 19, 2021
1 parent d8056a7 commit 871ea1d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions security/users_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_user(_kwargs: dict) -> Optional[UserModel]:
from google.cloud import ndb
with get_client().context():
_user_instance: Optional[UserModel] = UserModel.query(UserModel.uid == _kwargs['uid']).get()
if not isinstance(_user_instance, UserModel) and bool(_user_instance) and is_development():
if not isinstance(_user_instance, UserModel) or not bool(_user_instance):
_user_instance: UserModel = UserModel(**_kwargs)
_key: Optional[ndb.Key] = _user_instance.put()
# NOTE: ignoring key because it does not matter if internet is not on
Expand Down Expand Up @@ -134,7 +134,6 @@ def handle_users_auth(func):
and admin dashboard
:param func:
"""

# noinspection PyBroadException
@wraps(func)
def decorated(*args, **kwargs):
Expand All @@ -145,6 +144,7 @@ def decorated(*args, **kwargs):
:return:
"""
if is_development():
# TODO also do this on initial setup of application - could be triggered from admin application
current_user: Optional[UserModel] = get_admin_user()
return func(current_user, *args, **kwargs)

Expand Down Expand Up @@ -189,15 +189,12 @@ def logged_user(func):
:param func: route to wrap
:return: wrapped function
"""

@wraps(func)
def decorated(*args, **kwargs):
current_user: Optional[UserModel] = None
# NOTE: by passes authentication and returns admin user as authenticated
# user on development
if is_development():
# TODO use api here instead of user model

current_user: Optional[UserModel] = get_admin_user()
return func(current_user, *args, **kwargs)

Expand All @@ -218,7 +215,6 @@ def decorated(*args, **kwargs):
else:
pass
return func(current_user, *args, **kwargs)

return decorated


Expand Down

0 comments on commit 871ea1d

Please sign in to comment.