Enhance user role management and access control in the application. Added user management link in the navigation for admins. Updated login flow to redirect to Casdoor for authentication. Improved logging for user actions and unauthorized access attempts. Adjusted role checks across various views to include '管理员' and 'admin' for access permissions.
This commit is contained in:
+2
-18
@@ -9,26 +9,10 @@ def init_auth_routes(app):
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
# 如果已登录,直接跳转到仪表盘
|
||||
# 已登录直接进入仪表盘,否则跳转 Casdoor 登录
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
# 检查是否启用了 Casdoor
|
||||
casdoor_enabled = bool(app.config.get('CASDOOR_CLIENT_ID'))
|
||||
|
||||
# 处理手机号登录
|
||||
if request.method == 'POST':
|
||||
phone = request.form['phone']
|
||||
user = User.query.filter_by(phone=phone).first()
|
||||
if user:
|
||||
login_user(user)
|
||||
app.logger.info(f'用户 {user.name}({user.phone}) 登录成功')
|
||||
return redirect(url_for('dashboard'))
|
||||
else:
|
||||
app.logger.warning(f'登录失败:用户不存在 (手机号: {phone})')
|
||||
flash('用户不存在')
|
||||
|
||||
return render_template('login.html', casdoor_enabled=casdoor_enabled)
|
||||
return redirect(url_for('casdoor_login'))
|
||||
|
||||
@app.route('/casdoor/login')
|
||||
def casdoor_login():
|
||||
|
||||
Reference in New Issue
Block a user