From c91dafe1deacbf28a8032da716e2f69fa4ca4b19 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 29 Dec 2023 21:06:01 +0800 Subject: [PATCH] add auth --- server/routes/__init__.py | 1 + server/routes/team.py | 20 ++++++++++++++++++++ server/utils/auth.py | 13 +++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 server/routes/team.py create mode 100644 server/utils/auth.py diff --git a/server/routes/__init__.py b/server/routes/__init__.py index 25a22184..a7105778 100644 --- a/server/routes/__init__.py +++ b/server/routes/__init__.py @@ -1,2 +1,3 @@ from .github import * from .lark import * +from .team import * diff --git a/server/routes/team.py b/server/routes/team.py new file mode 100644 index 00000000..f32ed6da --- /dev/null +++ b/server/routes/team.py @@ -0,0 +1,20 @@ +import logging + +from app import app +from flask import Blueprint, abort, jsonify, redirect, request +from utils.auth import authenticated + +bp = Blueprint("team", __name__, url_prefix="/api/team") + + +@bp.route("/", methods=["GET"]) +@authenticated +def get_team_list(): + """ + get team list + TODO + """ + return jsonify({"code": 0, "msg": "success", "data": [], "total": 0}) + + +app.register_blueprint(bp) diff --git a/server/utils/auth.py b/server/utils/auth.py new file mode 100644 index 00000000..e008d6e5 --- /dev/null +++ b/server/utils/auth.py @@ -0,0 +1,13 @@ +from functools import wraps + +from flask import abort, session + + +def authenticated(func): + @wraps(func) + def wrapper(*args, **kwargs): + if "user_id" not in session: + return abort(401) + return func(*args, **kwargs) + + return wrapper