diff --git a/api/src/app.py b/api/src/app.py index a3323e3..00edb48 100644 --- a/api/src/app.py +++ b/api/src/app.py @@ -13,7 +13,7 @@ from function.google import secret_key from function.db import get_db -from function.loadconfig import config, UPLOAD_FOLDER +from function.loadconfig import config, UPLOAD_FOLDER, isDev # list route file @@ -37,7 +37,7 @@ def tree_route(startpath): app = Flask(__name__) -isDev = config['DEV'].lower() == "true" + if not isDev: CORS(app, supports_credentials=True, resources={r"/api/*": {"origins": config['DOMAIN']}}) else: diff --git a/api/src/function/loadconfig.py b/api/src/function/loadconfig.py index c0665a2..d18cccf 100644 --- a/api/src/function/loadconfig.py +++ b/api/src/function/loadconfig.py @@ -4,4 +4,6 @@ # load config config = dotenv_values("config/.env") -UPLOAD_FOLDER = os.path.join('files', 'UploadFile') \ No newline at end of file +UPLOAD_FOLDER = os.path.join('files', 'UploadFile') + +isDev = config['DEV'].lower() == "true" \ No newline at end of file diff --git a/api/src/route/api/glob/auth/checkauth_GET.py b/api/src/route/api/glob/auth/checkauth_GET.py index 6a056f0..6005fed 100644 --- a/api/src/route/api/glob/auth/checkauth_GET.py +++ b/api/src/route/api/glob/auth/checkauth_GET.py @@ -1,12 +1,28 @@ -from flask import jsonify, g +from flask import jsonify, g, request from flask_jwt_extended import jwt_required, get_jwt_identity +from function.loadconfig import isDev +from function.db import get_db + + +import pytz +from datetime import datetime + +gmt_timezone = pytz.timezone('Asia/Bangkok') + @jwt_required() def main(): email = get_jwt_identity()['email'] + conn = get_db() + cur = conn.cursor() - cur = g.db.cursor() + if not isDev: + # log ip + UID = email.split("@")[0] + query = "INSERT INTO `iplog` (`IP`, `UID`, `Timestamp`) VALUES (%s,%s,%s)" + cur.execute(query, (f"{request.headers.get('X-Real-IP')} ; {request.headers.get('X-Forwarded-For')}", UID, datetime.now(gmt_timezone))) + conn.commit() query = """ SELECT diff --git a/api/src/route/api/glob/auth/testCallback_POST.py b/api/src/route/api/glob/auth/testCallback_POST.py index ace793d..ec49237 100644 --- a/api/src/route/api/glob/auth/testCallback_POST.py +++ b/api/src/route/api/glob/auth/testCallback_POST.py @@ -5,14 +5,14 @@ from function.db import get_db import re -from function.loadconfig import config +from function.loadconfig import config, isDev from flask_jwt_extended import create_access_token, set_access_cookies, get_csrf_token regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b' def main(): - if not config['DEV'].lower() == "true": + if not isDev: return jsonify({ 'success': False, 'msg': '',