|
"""
|
|
API密钥管理系统 - 主应用文件
|
|
提供API密钥的添加、编辑、删除和管理功能
|
|
"""
|
|
from flask import Flask, redirect, url_for, request, jsonify
|
|
|
|
|
|
from config import SECRET_KEY
|
|
|
|
|
|
from routes.web import web_bp
|
|
from routes.api import api_bp
|
|
|
|
|
|
from utils.auth import AuthManager
|
|
|
|
|
|
app = Flask(__name__)
|
|
app.secret_key = SECRET_KEY
|
|
|
|
|
|
@app.before_request
|
|
def authenticate():
|
|
"""请求拦截器 - 验证所有需要认证的请求"""
|
|
|
|
if request.path == '/login' or request.path.startswith('/static/'):
|
|
return
|
|
|
|
|
|
token = request.cookies.get('auth_token')
|
|
|
|
|
|
if not AuthManager.verify_token(token):
|
|
|
|
if request.headers.get('X-Requested-With') == 'XMLHttpRequest' or request.path.startswith('/api/'):
|
|
return jsonify({"success": False, "error": "未授权访问"}), 401
|
|
|
|
return redirect(url_for('web.login'))
|
|
|
|
|
|
app.register_blueprint(web_bp)
|
|
app.register_blueprint(api_bp)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|