From 09a809192aceb70bf12f59237db928c443ddc423 Mon Sep 17 00:00:00 2001 From: Mattia Succurro Date: Mon, 28 Oct 2019 08:29:07 +0100 Subject: [PATCH] Some fixes --- app/models.py | 2 +- app/utils.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index a03ad7b..d03ea39 100644 --- a/app/models.py +++ b/app/models.py @@ -16,7 +16,7 @@ import os # here should go `from .utils import get_current_user`, but it will cause # import errors. It's instead imported at function level. -database = SqliteDatabase(os.path.join(os.getcwd(), 'coriplus.sqlite')) +database = SqliteDatabase(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'coriplus.sqlite')) class BaseModel(Model): class Meta: diff --git a/app/utils.py b/app/utils.py index f014d69..302cb3a 100644 --- a/app/utils.py +++ b/app/utils.py @@ -101,9 +101,14 @@ except OSError: # get the user from the session # changed in 0.5 to comply with flask_login def get_current_user(): - user_id = session.get('user_id') - if user_id: - return User[user_id] + # new in 0.7; need a different method to get current user id + if request.path.startswith('/api/'): + # assume token validation is already done + return User[request.args['access_token'].split(':')[0]] + else: + user_id = session.get('user_id') + if user_id: + return User[user_id] def push_notification(type, target, **kwargs): try: