@@ -81,7 +83,7 @@
// 你可以通过 admin.setConfigPath 方法修改配置文件位置
// 你可以通过 admin.setConfigType 方法修改配置文件类型
admin.setConfigType('json')
- admin.setConfigPath("{{ url_for('adminIndex.configs') }}")
+ admin.setConfigPath("{{ url_for('rights.configs') }}")
admin.render()
@@ -89,7 +91,7 @@
admin.logout(function () {
let loading = layer.load()
$.ajax({
- url: '/admin/logout',
+ url: '/passport/logout',
dataType: 'json',
type: 'post',
success: function (result) {
diff --git a/applications/templates/admin/login.html b/applications/templates/admin/login.html
index da7a49f..3cdaf9b 100644
--- a/applications/templates/admin/login.html
+++ b/applications/templates/admin/login.html
@@ -26,7 +26,7 @@
@@ -45,7 +45,7 @@
let layer = layui.layer;
let button = layui.button;
let popup = layui.popup;
- let captchaPath = "{{ url_for('adminIndex.get_captcha') }}";
+ let captchaPath = "{{ url_for('passport.get_captcha') }}";
form.on('submit(login)', function (data) {
let loader = layer.load();
@@ -59,7 +59,7 @@
btn.stop(function () {
if (result.success) {
popup.success(result.msg, function () {
- location.href = "{{ url_for('adminIndex.index') }}";
+ location.href = "{{ url_for('admin.index') }}";
})
} else {
popup.failure(result.msg, function () {
@@ -81,7 +81,7 @@
})
diff --git a/applications/templates/admin/user/edit.html b/applications/templates/admin/user/edit.html
index f5d3a0e..ecf6ba2 100644
--- a/applications/templates/admin/user/edit.html
+++ b/applications/templates/admin/user/edit.html
@@ -78,7 +78,7 @@
dtree.renderSelect({
elem: '#selectParent',
- url: '/admin/dept/tree',
+ url: '/dept/tree',
method: 'get',
selectInputName: { nodeId: 'deptId', context: 'deptName' },
skin: 'layui',
diff --git a/applications/templates/admin/user/main.html b/applications/templates/admin/user/main.html
index b6465c6..8ed4d7e 100644
--- a/applications/templates/admin/user/main.html
+++ b/applications/templates/admin/user/main.html
@@ -146,7 +146,7 @@
dtree.render({
elem: '#dept-tree',
method: 'get',
- url: '/admin/dept/tree',
+ url: '/dept/tree',
dataFormat: 'list',
line: true,
skin: 'laySimple',
diff --git a/applications/view/__init__.py b/applications/view/__init__.py
index 1fbc819..bec7989 100644
--- a/applications/view/__init__.py
+++ b/applications/view/__init__.py
@@ -1,7 +1,13 @@
-from applications.view.admin import init_admin_views
-from applications.view.index import init_index_views
+from applications.view.admin import register_admin_views
+from applications.view.index import register_index_views
+from applications.view.passport import register_passport_views
+from applications.view.rights import register_rights_view
+from applications.view.department import register_dept_views
def init_view(app):
- init_admin_views(app)
- init_index_views(app)
+ register_admin_views(app)
+ register_index_views(app)
+ register_rights_view(app)
+ register_passport_views(app)
+ register_dept_views(app)
diff --git a/applications/view/admin/__init__.py b/applications/view/admin/__init__.py
index 3af6e2c..ebb9b47 100644
--- a/applications/view/admin/__init__.py
+++ b/applications/view/admin/__init__.py
@@ -1,9 +1,8 @@
from flask import Flask
from applications.view.admin.admin_log import admin_log
-from applications.view.admin.dept import admin_dept
from applications.view.admin.dict import admin_dict
-from applications.view.admin.index import admin_index
+from applications.view.admin.index import admin_bp
from applications.view.admin.file import admin_file
from applications.view.admin.power import admin_power
from applications.view.admin.role import admin_role
@@ -11,8 +10,8 @@ from applications.view.admin.user import admin_user
from applications.view.admin.monitor import admin_monitor_bp
-def init_admin_views(app: Flask):
- app.register_blueprint(admin_index)
+def register_admin_views(app: Flask):
+ app.register_blueprint(admin_bp)
app.register_blueprint(admin_user)
app.register_blueprint(admin_file)
app.register_blueprint(admin_monitor_bp)
@@ -20,4 +19,3 @@ def init_admin_views(app: Flask):
app.register_blueprint(admin_power)
app.register_blueprint(admin_role)
app.register_blueprint(admin_dict)
- app.register_blueprint(admin_dept)
diff --git a/applications/view/admin/index.py b/applications/view/admin/index.py
index efe91db..b4dde3f 100644
--- a/applications/view/admin/index.py
+++ b/applications/view/admin/index.py
@@ -1,100 +1,19 @@
-from flask import Blueprint, render_template, jsonify, request, session, redirect, url_for
-from flask_login import login_user, login_required, logout_user, current_user
-from applications.common.admin import index_curd
-from applications.common.admin_log import login_log
-from applications.common.utils.http import fail_api, success_api
-from applications.models import User
+from flask import Blueprint, render_template
+from flask_login import login_required, current_user
-admin_index = Blueprint('adminIndex', __name__, url_prefix='/admin')
+admin_bp = Blueprint('admin', __name__, url_prefix='/admin')
# 首页
-@admin_index.get('/')
+@admin_bp.get('/')
@login_required
def index():
user = current_user
return render_template('admin/index.html', user=user)
-# 渲染配置
-@admin_index.get('/configs')
-@login_required
-def configs():
- return index_curd.get_render_config()
-
-
-# 获取验证码
-@admin_index.get('/getCaptcha')
-def get_captcha():
- resp, code = index_curd.get_captcha()
- session["code"] = code
- return resp
-
-
-# 登录
-@admin_index.get('/login')
-def login():
- if current_user.is_authenticated:
- return redirect(url_for('adminIndex.index'))
- return render_template('admin/login.html')
-
-
-# 登录
-@admin_index.post('/login')
-def login_post():
- req = request.form
- username = req.get('username')
- password = req.get('password')
- code = req.get('captcha')
-
- if not username or not password or not code:
- return fail_api(msg="用户名或密码没有输入")
- s_code = session.get("code", None)
-
- if not all([code, s_code]):
- return fail_api(msg="参数错误")
-
- if code != s_code:
- return fail_api(msg="验证码错误")
- user = User.query.filter_by(username=username).first()
-
- if user is None:
- return fail_api(msg="不存在的用户")
-
- if user.enable is 0:
- return fail_api(msg="用户被暂停使用")
-
- if username == user.username and user.validate_password(password):
- # 登录
- login_user(user)
- # 记录登录日志
- login_log(request, uid=user.id, is_access=True)
- # 存入权限
- index_curd.add_auth_session()
- return success_api(msg="登录成功")
- login_log(request, uid=user.id, is_access=False)
- return fail_api(msg="用户名或密码错误")
-
-
-# 退出登录
-@admin_index.post('/logout')
-@login_required
-def logout():
- logout_user()
- session.pop('permissions')
- return success_api(msg="注销成功")
-
-
-# 菜单
-@admin_index.get('/menu')
-@login_required
-def menu():
- menu_tree = index_curd.make_menu_tree()
- return jsonify(menu_tree)
-
-
# 控制台页面
-@admin_index.get('/welcome')
+@admin_bp.get('/welcome')
@login_required
def welcome():
return render_template('admin/console/console.html')
diff --git a/applications/view/admin/dept.py b/applications/view/department/__init__.py
similarity index 87%
rename from applications/view/admin/dept.py
rename to applications/view/department/__init__.py
index fccd726..677dc8e 100644
--- a/applications/view/admin/dept.py
+++ b/applications/view/department/__init__.py
@@ -7,16 +7,20 @@ from applications.common.utils.validate import check_data
from applications.models import DeptSchema
from applications.common.admin import dept_curd as dept_curd
-admin_dept = Blueprint('adminDept', __name__, url_prefix='/admin/dept')
+dept_bp = Blueprint('dept', __name__, url_prefix='/dept')
-@admin_dept.get('/')
+def register_dept_views(app):
+ app.register_blueprint(dept_bp)
+
+
+@dept_bp.get('/')
@authorize("admin:dept:main", log=True)
def main():
return render_template('admin/dept/main.html')
-@admin_dept.get('/data')
+@dept_bp.get('/data')
@authorize("admin:dept:main", log=True)
def data():
power_data = dept_curd.get_dept_dict()
@@ -26,13 +30,13 @@ def data():
return jsonify(res)
-@admin_dept.get('/add')
+@dept_bp.get('/add')
@authorize("admin:dept:add", log=True)
def add():
return render_template('admin/dept/add.html')
-@admin_dept.get('/tree')
+@dept_bp.get('/tree')
@authorize("admin:dept:main", log=True)
def tree():
power_data = dept_curd.get_dept_dict()
@@ -44,7 +48,7 @@ def tree():
return jsonify(res)
-@admin_dept.post('/save')
+@dept_bp.post('/save')
@authorize("admin:dept:add", log=True)
def save():
req = request.json
@@ -53,7 +57,7 @@ def save():
return success_api(msg="成功")
-@admin_dept.get('/edit')
+@dept_bp.get('/edit')
@authorize("admin:dept:edit", log=True)
def edit():
_id = request.args.get("deptId")
@@ -62,7 +66,7 @@ def edit():
# 启用
-@admin_dept.put('/enable')
+@dept_bp.put('/enable')
@authorize("admin:dept:edit", log=True)
def enable():
_id = request.json.get('deptId')
@@ -75,7 +79,7 @@ def enable():
# 禁用
-@admin_dept.put('/disable')
+@dept_bp.put('/disable')
@authorize("admin:dept:edit", log=True)
def dis_enable():
_id = request.json.get('deptId')
@@ -87,7 +91,7 @@ def dis_enable():
return fail_api(msg="数据错误")
-@admin_dept.put('/update')
+@dept_bp.put('/update')
@authorize("admin:dept:edit", log=True)
def update():
req = request.json
@@ -98,7 +102,7 @@ def update():
return success_api(msg="更新成功")
-@admin_dept.delete('/remove/')
+@dept_bp.delete('/remove/')
@authorize("admin:dept:remove", log=True)
def remove(_id):
res = dept_curd.remove_dept(_id)
diff --git a/applications/view/index/__init__.py b/applications/view/index/__init__.py
index 98bc06a..382c14f 100644
--- a/applications/view/index/__init__.py
+++ b/applications/view/index/__init__.py
@@ -5,7 +5,7 @@ index_bp = Blueprint('Index', __name__, url_prefix='/')
from . import index
-def init_index_views(app):
+def register_index_views(app):
"""
初始化蓝图
diff --git a/applications/view/passport/__init__.py b/applications/view/passport/__init__.py
new file mode 100644
index 0000000..7a4cd0f
--- /dev/null
+++ b/applications/view/passport/__init__.py
@@ -0,0 +1,75 @@
+from flask import Blueprint, session, redirect, url_for, render_template, request
+from flask_login import current_user, login_user, login_required, logout_user
+
+from applications.common.admin import index_curd
+from applications.common.admin_log import login_log
+from applications.common.utils.http import fail_api, success_api
+from applications.models import User
+
+passport_bp = Blueprint('passport', __name__, url_prefix='/passport')
+
+
+def register_passport_views(app):
+ app.register_blueprint(passport_bp)
+
+
+# 获取验证码
+@passport_bp.get('/getCaptcha')
+def get_captcha():
+ resp, code = index_curd.get_captcha()
+ session["code"] = code
+ return resp
+
+
+# 登录
+@passport_bp.get('/login')
+def login():
+ if current_user.is_authenticated:
+ return redirect(url_for('admin.index'))
+ return render_template('admin/login.html')
+
+
+# 登录
+@passport_bp.post('/login')
+def login_post():
+ req = request.form
+ username = req.get('username')
+ password = req.get('password')
+ code = req.get('captcha')
+
+ if not username or not password or not code:
+ return fail_api(msg="用户名或密码没有输入")
+ s_code = session.get("code", None)
+
+ if not all([code, s_code]):
+ return fail_api(msg="参数错误")
+
+ if code != s_code:
+ return fail_api(msg="验证码错误")
+ user = User.query.filter_by(username=username).first()
+
+ if user is None:
+ return fail_api(msg="不存在的用户")
+
+ if user.enable is 0:
+ return fail_api(msg="用户被暂停使用")
+
+ if username == user.username and user.validate_password(password):
+ # 登录
+ login_user(user)
+ # 记录登录日志
+ login_log(request, uid=user.id, is_access=True)
+ # 存入权限
+ index_curd.add_auth_session()
+ return success_api(msg="登录成功")
+ login_log(request, uid=user.id, is_access=False)
+ return fail_api(msg="用户名或密码错误")
+
+
+# 退出登录
+@passport_bp.post('/logout')
+@login_required
+def logout():
+ logout_user()
+ session.pop('permissions')
+ return success_api(msg="注销成功")
diff --git a/applications/view/rights/__init__.py b/applications/view/rights/__init__.py
new file mode 100644
index 0000000..0293dbd
--- /dev/null
+++ b/applications/view/rights/__init__.py
@@ -0,0 +1,9 @@
+from flask import Blueprint, Flask
+
+rights_bp = Blueprint('rights', __name__, url_prefix='/rights')
+
+from . import routes
+
+
+def register_rights_view(app: Flask):
+ app.register_blueprint(rights_bp)
diff --git a/applications/view/rights/routes.py b/applications/view/rights/routes.py
new file mode 100644
index 0000000..be6f42e
--- /dev/null
+++ b/applications/view/rights/routes.py
@@ -0,0 +1,20 @@
+# 渲染配置
+from flask import jsonify
+from flask_login import login_required
+
+from . import rights_bp
+from ...common.admin import index_curd
+
+
+@rights_bp.get('/configs')
+@login_required
+def configs():
+ return index_curd.get_render_config()
+
+
+# 菜单
+@rights_bp.get('/menu')
+@login_required
+def menu():
+ menu_tree = index_curd.make_menu_tree()
+ return jsonify(menu_tree)
diff --git a/test/pear.sql b/test/pear.sql
index 7c81c7b..0e666e4 100644
--- a/test/pear.sql
+++ b/test/pear.sql
@@ -177,7 +177,7 @@ INSERT INTO `admin_power` VALUES (44, '数据字典', '1', 'admin:dict:main', '/
INSERT INTO `admin_power` VALUES (45, '字典增加', '2', 'admin:dict:add', '', '', '44', 'layui-icon ', 1, '2021-04-16 14:00:59', '2021-04-16 14:00:59', 1);
INSERT INTO `admin_power` VALUES (46, '字典修改', '2', 'admin:dict:edit', '', '', '44', 'layui-icon ', 2, '2021-04-16 14:01:33', '2021-04-16 14:01:33', 1);
INSERT INTO `admin_power` VALUES (47, '字典删除', '2', 'admin:dict:remove', '', '', '44', 'layui-icon ', 3, '2021-04-16 14:02:06', '2021-04-16 14:02:06', 1);
-INSERT INTO `admin_power` VALUES (48, '部门管理', '1', 'admin:dept:main', '/admin/dept', '_iframe', '1', 'layui-icon layui-icon-group', 3, '2021-06-01 16:22:11', '2021-06-01 16:22:11', 1);
+INSERT INTO `admin_power` VALUES (48, '部门管理', '1', 'admin:dept:main', '/dept', '_iframe', '1', 'layui-icon layui-icon-group', 3, '2021-06-01 16:22:11', '2021-06-01 16:22:11', 1);
INSERT INTO `admin_power` VALUES (49, '部门增加', '2', 'admin:dept:add', '', '', '48', 'layui-icon None', 1, '2021-06-01 17:35:52', '2021-06-01 17:36:15', 1);
INSERT INTO `admin_power` VALUES (50, '部门编辑', '2', 'admin:dept:edit', '', '', '48', 'layui-icon ', 2, '2021-06-01 17:36:41', '2021-06-01 17:36:41', 1);
INSERT INTO `admin_power` VALUES (51, '部门删除', '2', 'admin:dept:remove', '', '', '48', 'layui-icon None', 3, '2021-06-01 17:37:15', '2021-06-01 17:37:26', 1);