chore: add .gitignore, clean tracked junk files

This commit is contained in:
2026-05-29 08:33:35 +08:00
parent 2d5c5d4c0d
commit 1ccb116f80
53 changed files with 189 additions and 2445 deletions
+29 -5
View File
@@ -13,8 +13,8 @@ def init_auth_routes(app):
# 如果已登录,直接跳转到仪表盘
if current_user.is_authenticated:
return redirect(url_for('dashboard'))
# 未登录直接跳转 Casdoor 登录页
return redirect(url_for('casdoor_login'))
# 未登录展示登录页(登录页会自动跳转 Casdoor,如有错误提示则不跳转)
return render_template('login.html')
@app.route('/casdoor/login')
def casdoor_login():
@@ -65,18 +65,44 @@ def init_auth_routes(app):
flash('登录失败:无法获取用户信息')
return redirect(url_for('login'))
# 获取完整账户信息(包含标签)
account_info = casdoor_auth.get_account_info(access_token)
if not account_info:
app.logger.error('获取 Casdoor 账户信息失败')
flash('登录失败:无法获取账户信息')
return redirect(url_for('login'))
# 从 Casdoor 用户信息中提取数据
# Casdoor 返回的用户信息可能包含:name, email, phone, id 等字段
casdoor_id = user_info.get('sub') or user_info.get('id') or user_info.get('name')
phone = user_info.get('phone') or user_info.get('phoneNumber') or casdoor_id
name = user_info.get('name') or user_info.get('displayName') or '未知用户'
# 基于标签的访问控制:用户标签必须等于项目名
project_name = app.config.get('PROJECT_NAME')
if not project_name:
app.logger.error('未配置 PROJECT_NAME 环境变量,拒绝登录')
flash('登录失败:未配置项目名')
return redirect(url_for('login'))
raw_tags = account_info.get('tag') or account_info.get('tags')
if isinstance(raw_tags, str):
user_tags = [t.strip() for t in raw_tags.split(',') if t.strip()]
elif isinstance(raw_tags, list):
user_tags = [str(t).strip() for t in raw_tags if str(t).strip()]
else:
user_tags = []
if project_name not in user_tags:
app.logger.warning(f'用户 {name}({phone}) 标签 {user_tags} 不匹配项目 {project_name}')
flash('您没有本系统的访问权限,请联系管理员处理')
return redirect(url_for('login'))
app.logger.info(f'Casdoor 用户信息: {user_info}')
# 查找或创建本地用户
user = User.query.filter_by(phone=phone).first()
if not user:
# 如果用户不存在,创建新用户
user = User(
phone=phone,
name=name,
@@ -87,7 +113,6 @@ def init_auth_routes(app):
db.session.commit()
app.logger.info(f'创建新用户: {name}({phone})')
else:
# 更新用户信息
user.name = name
if user_info.get('affiliation'):
user.branch = user_info.get('affiliation')
@@ -96,7 +121,6 @@ def init_auth_routes(app):
db.session.commit()
app.logger.info(f'更新用户信息: {name}({phone})')
# 登录用户
login_user(user)
app.logger.info(f'用户 {user.name}({user.phone}) 通过 Casdoor 登录成功')