feat: generate permission sql for stocktake modules and implement single-device login restriction
This commit is contained in:
@ -3,6 +3,7 @@ from flask_migrate import Migrate
|
||||
from flask_cors import CORS
|
||||
from flask_jwt_extended import JWTManager # 确保引入了 JWTManager
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import redis
|
||||
|
||||
# 1. 创建扩展实例(此时未绑定具体的 App)
|
||||
db = SQLAlchemy()
|
||||
@ -10,6 +11,9 @@ migrate = Migrate()
|
||||
cors = CORS()
|
||||
jwt = JWTManager() # 必须实例化
|
||||
|
||||
# Redis 客户端 (单设备登录互踢用)
|
||||
redis_client = None
|
||||
|
||||
|
||||
def beijing_time():
|
||||
"""获取北京时间 (UTC+8)"""
|
||||
@ -21,6 +25,8 @@ def init_extensions(app):
|
||||
"""
|
||||
统一初始化所有 Flask 扩展
|
||||
"""
|
||||
global redis_client
|
||||
|
||||
# 初始化数据库
|
||||
db.init_app(app)
|
||||
|
||||
@ -31,4 +37,13 @@ def init_extensions(app):
|
||||
cors.init_app(app, resources={r"/api/*": {"origins": "*"}})
|
||||
|
||||
# 初始化 JWT (这一步至关重要,缺少它会导致 500 错误)
|
||||
jwt.init_app(app)
|
||||
jwt.init_app(app)
|
||||
|
||||
# 初始化 Redis (单设备登录互踢)
|
||||
redis_url = app.config.get('REDIS_URL', 'redis://localhost:6379/0')
|
||||
try:
|
||||
redis_client = redis.from_url(redis_url, decode_responses=True)
|
||||
redis_client.ping()
|
||||
app.logger.info("✅ Redis connected successfully")
|
||||
except Exception as e:
|
||||
app.logger.warning(f"⚠️ Redis connection failed: {e}, single-device login will be disabled")
|
||||
Reference in New Issue
Block a user