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:
2025-12-10 15:53:17 +08:00
parent bb39314940
commit 0bb323bbff
24 changed files with 1285 additions and 61 deletions
+4 -1
View File
@@ -35,7 +35,7 @@
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 nav_menu">
{% if current_user.is_authenticated %}
{% if current_user.role == '统计员' %}
{% if current_user.role in ['统计员', '管理员', 'admin'] or current_user.name == 'Admin' %}
<li class="nav-item">
<a class="nav_link {{ 'active' if request.endpoint == 'dashboard' }}" href="{{ url_for('dashboard') }}">仪表盘</a>
</li>
@@ -57,6 +57,9 @@
<li class="nav-item">
<a class="nav_link {{ 'active' if request.endpoint == 'about' }}" href="{{ url_for('about') }}">关于</a>
</li>
<li class="nav-item">
<a class="nav_link {{ 'active' if request.endpoint == 'user_list' }}" href="{{ url_for('user_list') }}">用户管理</a>
</li>
{% elif current_user.role == '装维员' %}
<li class="nav-item">
<a class="nav_link {{ 'active' if request.endpoint == 'dashboard' }}" href="{{ url_for('dashboard') }}">仪表盘</a>
+18 -33
View File
@@ -5,40 +5,25 @@
<h2 class="login_title">欢迎使用</h2>
<div class="login_subtitle">大化重点项目工单管理平台</div>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="login_error">
{% for message in messages %}
{{ message }}
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% if casdoor_enabled %}
<!-- Casdoor 登录按钮 -->
<div class="login_casdoor_section">
<a href="{{ url_for('casdoor_login') }}" class="login_button login_button_casdoor">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="margin-right: 8px;">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" fill="currentColor"/>
</svg>
使用 Casdoor 登录
</a>
</div>
<div class="login_divider">
<span></span>
</div>
{% endif %}
<!-- 原有手机号登录表单 -->
<form method="POST" class="login_form">
<div class="login_input_group">
<label for="phone" class="login_label">用户名(手机号)</label>
<input type="text" id="phone" name="phone" class="login_input" placeholder="请输入手机号" required>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="login_error">
{% for message in messages %}
{{ message }}
{% endfor %}
</div>
<button type="submit" class="login_button login_button_phone">手机号登录</button>
</form>
{% endif %}
{% endwith %}
<!-- Casdoor 登录按钮 -->
<div class="login_casdoor_section">
<a href="{{ url_for('casdoor_login') }}" class="login_button login_button_casdoor">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="margin-right: 8px;">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" fill="currentColor"/>
</svg>
使用 Casdoor 登录
</a>
</div>
</div>
</div>
{% endblock %}
+59
View File
@@ -0,0 +1,59 @@
{% extends "base.html" %}
{% block content %}
<div class="container mt-4">
<h2 class="mb-3">用户管理</h2>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="alert alert-info">
{% for message in messages %}
{{ message }}
{% endfor %}
</div>
{% endif %}
{% endwith %}
<div class="table-responsive">
<table class="table table-bordered align-middle">
<thead class="table-light">
<tr>
<th>手机号</th>
<th>姓名</th>
<th>所属支局</th>
<th>角色</th>
<th style="width: 160px;">操作</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<form method="POST" action="{{ url_for('update_user', phone=user.phone) }}">
<td>{{ user.phone }}</td>
<td>{{ user.name }}</td>
<td>
<select name="branch" class="form-select">
<option value="" {% if not user.branch %}selected{% endif %}>未设置</option>
{% for branch in branch_options %}
<option value="{{ branch }}" {% if user.branch == branch %}selected{% endif %}>{{ branch }}</option>
{% endfor %}
</select>
</td>
<td>
<select name="role" class="form-select" required>
{% for role in role_options %}
<option value="{{ role }}" {% if user.role == role %}selected{% endif %}>{{ role }}</option>
{% endfor %}
</select>
</td>
<td class="text-center">
<button type="submit" class="btn btn-primary btn-sm">保存</button>
</td>
</form>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}