将权限与部门的逻辑分包
This commit is contained in:
@@ -28,21 +28,27 @@ def make_menu_tree():
|
|||||||
# power1 = Power.query.filter(
|
# power1 = Power.query.filter(
|
||||||
# Power.type == 1
|
# Power.type == 1
|
||||||
# ).all()
|
# ).all()
|
||||||
|
# 获取当前用户的角色
|
||||||
role = current_user.role
|
role = current_user.role
|
||||||
power0 = []
|
power0 = []
|
||||||
power1 = []
|
power1 = []
|
||||||
for i in role:
|
for i in role:
|
||||||
|
# 如果角色没有被启用就直接跳过
|
||||||
if i.enable == 0:
|
if i.enable == 0:
|
||||||
continue
|
continue
|
||||||
|
# 变量角色用户的权限
|
||||||
for p in i.power:
|
for p in i.power:
|
||||||
|
# 如果权限关闭了就直接跳过
|
||||||
if p.enable == 0:
|
if p.enable == 0:
|
||||||
continue
|
continue
|
||||||
|
# 一级菜单
|
||||||
if int(p.type) == 0:
|
if int(p.type) == 0:
|
||||||
power0.append(p)
|
power0.append(p)
|
||||||
|
# 二级菜单
|
||||||
else:
|
else:
|
||||||
power1.append(p)
|
power1.append(p)
|
||||||
|
|
||||||
power_schema = PowerSchema(many=True) # 用已继承ma.ModelSchema类的自定制类生成序列化类
|
power_schema = PowerSchema(many=True) # 用已继承 ma.ModelSchema 类的自定制类生成序列化类
|
||||||
power0_dict = power_schema.dump(power0) # 生成可序列化对象
|
power0_dict = power_schema.dump(power0) # 生成可序列化对象
|
||||||
power1_dict = power_schema.dump(power1) # 生成可序列化对象
|
power1_dict = power_schema.dump(power1) # 生成可序列化对象
|
||||||
power0_dict = sorted(power0_dict, key=lambda i: i['sort'])
|
power0_dict = sorted(power0_dict, key=lambda i: i['sort'])
|
||||||
@@ -84,7 +90,7 @@ def get_render_config():
|
|||||||
# 菜单配置
|
# 菜单配置
|
||||||
}, menu={
|
}, menu={
|
||||||
# 菜单数据来源
|
# 菜单数据来源
|
||||||
"data": "/admin/menu",
|
"data": "/rights/menu",
|
||||||
"collaspe": True,
|
"collaspe": True,
|
||||||
# 是否同时只打开一个菜单目录
|
# 是否同时只打开一个菜单目录
|
||||||
"accordion": True,
|
"accordion": True,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from .init_error_views import init_error_views
|
|||||||
|
|
||||||
|
|
||||||
def init_plugs(app: Flask) -> None:
|
def init_plugs(app: Flask) -> None:
|
||||||
init_debug_tool(app)
|
# init_debug_tool(app)
|
||||||
init_login_manager(app)
|
init_login_manager(app)
|
||||||
init_databases(app)
|
init_databases(app)
|
||||||
init_template_directives(app)
|
init_template_directives(app)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ def init_login_manager(app):
|
|||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
|
|
||||||
login_manager.login_view = 'adminIndex.login'
|
login_manager.login_view = 'passport.login'
|
||||||
login_manager.login_message = u'请登录以访问此页面'
|
login_manager.login_message = u'请登录以访问此页面'
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
dtree.renderSelect({
|
dtree.renderSelect({
|
||||||
elem: '#selectParent',
|
elem: '#selectParent',
|
||||||
url: '/admin/dept/tree',
|
url: '/dept/tree',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
selectInputName: { nodeId: 'parentId', context: 'parentName' },
|
selectInputName: { nodeId: 'parentId', context: 'parentName' },
|
||||||
skin: 'layui',
|
skin: 'layui',
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
|
|
||||||
form.on('submit(dept-save)', function (data) {
|
form.on('submit(dept-save)', function (data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/admin/dept/save',
|
url: '/dept/save',
|
||||||
data: JSON.stringify(data.field),
|
data: JSON.stringify(data.field),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
|
|||||||
@@ -99,7 +99,7 @@
|
|||||||
|
|
||||||
form.on('submit(dept-update)', function (data) {
|
form.on('submit(dept-update)', function (data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/admin/dept/update',
|
url: '/dept/update',
|
||||||
data: JSON.stringify(data.field),
|
data: JSON.stringify(data.field),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
let treetable = layui.treetable
|
let treetable = layui.treetable
|
||||||
let popup = layui.popup
|
let popup = layui.popup
|
||||||
|
|
||||||
let MODULE_PATH = '/admin/dept/'
|
let MODULE_PATH = '/dept/'
|
||||||
|
|
||||||
window.render = function () {
|
window.render = function () {
|
||||||
treetable.render({
|
treetable.render({
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
treeDefaultClose: false,
|
treeDefaultClose: false,
|
||||||
toolbar: '#dept-toolbar',
|
toolbar: '#dept-toolbar',
|
||||||
elem: '#dept-table',
|
elem: '#dept-table',
|
||||||
url: '/admin/dept/data',
|
url: '/dept/data',
|
||||||
page: false,
|
page: false,
|
||||||
cols: [
|
cols: [
|
||||||
[
|
[
|
||||||
@@ -153,7 +153,8 @@
|
|||||||
} else if (obj.event === 'refresh') {
|
} else if (obj.event === 'refresh') {
|
||||||
window.refresh()
|
window.refresh()
|
||||||
} else if (obj.event === 'batchRemove') {
|
} else if (obj.event === 'batchRemove') {
|
||||||
window.batchRemove(obj)
|
{#window.batchRemove(obj)#}
|
||||||
|
console.log(table.checkStatus(obj.config.id).data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -166,7 +167,7 @@
|
|||||||
}
|
}
|
||||||
let loading = layer.load()
|
let loading = layer.load()
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/admin/dept/' + operate,
|
url: '/dept/' + operate,
|
||||||
data: JSON.stringify({ deptId: this.value }),
|
data: JSON.stringify({ deptId: this.value }),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
|
|||||||
@@ -24,10 +24,12 @@
|
|||||||
<!-- 顶 部 右 侧 菜 单 -->
|
<!-- 顶 部 右 侧 菜 单 -->
|
||||||
<div id="control" class="layui-layout-control"></div>
|
<div id="control" class="layui-layout-control"></div>
|
||||||
<ul class="layui-nav layui-layout-right">
|
<ul class="layui-nav layui-layout-right">
|
||||||
<li class="layui-nav-item layui-hide-xs"><a href="#"
|
<li class="layui-nav-item layui-hide-xs">
|
||||||
class="fullScreen layui-icon layui-icon-screen-full"></a></li>
|
<a href="#" class="fullScreen layui-icon layui-icon-screen-full"></a>
|
||||||
<li class="layui-nav-item layui-hide-xs"><a href="http://www.pearadmin.com"
|
</li>
|
||||||
class="layui-icon layui-icon-website"></a></li>
|
<li class="layui-nav-item layui-hide-xs">
|
||||||
|
<a href="http://www.pearadmin.com" class="layui-icon layui-icon-website"></a>
|
||||||
|
</li>
|
||||||
<li class="layui-nav-item layui-hide-xs message"></li>
|
<li class="layui-nav-item layui-hide-xs message"></li>
|
||||||
<li class="layui-nav-item user">
|
<li class="layui-nav-item user">
|
||||||
<!-- 头 像 -->
|
<!-- 头 像 -->
|
||||||
@@ -81,7 +83,7 @@
|
|||||||
// 你可以通过 admin.setConfigPath 方法修改配置文件位置
|
// 你可以通过 admin.setConfigPath 方法修改配置文件位置
|
||||||
// 你可以通过 admin.setConfigType 方法修改配置文件类型
|
// 你可以通过 admin.setConfigType 方法修改配置文件类型
|
||||||
admin.setConfigType('json')
|
admin.setConfigType('json')
|
||||||
admin.setConfigPath("{{ url_for('adminIndex.configs') }}")
|
admin.setConfigPath("{{ url_for('rights.configs') }}")
|
||||||
|
|
||||||
admin.render()
|
admin.render()
|
||||||
|
|
||||||
@@ -89,7 +91,7 @@
|
|||||||
admin.logout(function () {
|
admin.logout(function () {
|
||||||
let loading = layer.load()
|
let loading = layer.load()
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/admin/logout',
|
url: '/passport/logout',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
type: 'post',
|
type: 'post',
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<input placeholder="验证码 : " name="captcha" hover class="code layui-input layui-input-inline"/>
|
<input placeholder="验证码 : " name="captcha" hover class="code layui-input layui-input-inline"/>
|
||||||
<img src="{{ url_for('adminIndex.get_captcha') }}" class="codeImage" id="captchaImage"/>
|
<img src="{{ url_for('passport.get_captcha') }}" class="codeImage" id="captchaImage"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<input type="checkbox" name="remember-me" title="记住密码" lay-skin="primary">
|
<input type="checkbox" name="remember-me" title="记住密码" lay-skin="primary">
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
let layer = layui.layer;
|
let layer = layui.layer;
|
||||||
let button = layui.button;
|
let button = layui.button;
|
||||||
let popup = layui.popup;
|
let popup = layui.popup;
|
||||||
let captchaPath = "{{ url_for('adminIndex.get_captcha') }}";
|
let captchaPath = "{{ url_for('passport.get_captcha') }}";
|
||||||
|
|
||||||
form.on('submit(login)', function (data) {
|
form.on('submit(login)', function (data) {
|
||||||
let loader = layer.load();
|
let loader = layer.load();
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
btn.stop(function () {
|
btn.stop(function () {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
popup.success(result.msg, function () {
|
popup.success(result.msg, function () {
|
||||||
location.href = "{{ url_for('adminIndex.index') }}";
|
location.href = "{{ url_for('admin.index') }}";
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
popup.failure(result.msg, function () {
|
popup.failure(result.msg, function () {
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
if (window != top) {
|
if (window !== top) {
|
||||||
top.location.href = location.href;
|
top.location.href = location.href;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
|
|
||||||
dtree.renderSelect({
|
dtree.renderSelect({
|
||||||
elem: '#selectParent',
|
elem: '#selectParent',
|
||||||
url: '/admin/dept/tree',
|
url: '/dept/tree',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
selectInputName: { nodeId: 'deptId', context: 'deptName' },
|
selectInputName: { nodeId: 'deptId', context: 'deptName' },
|
||||||
skin: 'layui',
|
skin: 'layui',
|
||||||
|
|||||||
@@ -146,7 +146,7 @@
|
|||||||
dtree.render({
|
dtree.render({
|
||||||
elem: '#dept-tree',
|
elem: '#dept-tree',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: '/admin/dept/tree',
|
url: '/dept/tree',
|
||||||
dataFormat: 'list',
|
dataFormat: 'list',
|
||||||
line: true,
|
line: true,
|
||||||
skin: 'laySimple',
|
skin: 'laySimple',
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
from applications.view.admin import init_admin_views
|
from applications.view.admin import register_admin_views
|
||||||
from applications.view.index import init_index_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):
|
def init_view(app):
|
||||||
init_admin_views(app)
|
register_admin_views(app)
|
||||||
init_index_views(app)
|
register_index_views(app)
|
||||||
|
register_rights_view(app)
|
||||||
|
register_passport_views(app)
|
||||||
|
register_dept_views(app)
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
from applications.view.admin.admin_log import admin_log
|
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.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.file import admin_file
|
||||||
from applications.view.admin.power import admin_power
|
from applications.view.admin.power import admin_power
|
||||||
from applications.view.admin.role import admin_role
|
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
|
from applications.view.admin.monitor import admin_monitor_bp
|
||||||
|
|
||||||
|
|
||||||
def init_admin_views(app: Flask):
|
def register_admin_views(app: Flask):
|
||||||
app.register_blueprint(admin_index)
|
app.register_blueprint(admin_bp)
|
||||||
app.register_blueprint(admin_user)
|
app.register_blueprint(admin_user)
|
||||||
app.register_blueprint(admin_file)
|
app.register_blueprint(admin_file)
|
||||||
app.register_blueprint(admin_monitor_bp)
|
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_power)
|
||||||
app.register_blueprint(admin_role)
|
app.register_blueprint(admin_role)
|
||||||
app.register_blueprint(admin_dict)
|
app.register_blueprint(admin_dict)
|
||||||
app.register_blueprint(admin_dept)
|
|
||||||
|
|||||||
@@ -1,100 +1,19 @@
|
|||||||
from flask import Blueprint, render_template, jsonify, request, session, redirect, url_for
|
from flask import Blueprint, render_template
|
||||||
from flask_login import login_user, login_required, logout_user, current_user
|
from flask_login import login_required, 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
|
|
||||||
|
|
||||||
admin_index = Blueprint('adminIndex', __name__, url_prefix='/admin')
|
admin_bp = Blueprint('admin', __name__, url_prefix='/admin')
|
||||||
|
|
||||||
|
|
||||||
# 首页
|
# 首页
|
||||||
@admin_index.get('/')
|
@admin_bp.get('/')
|
||||||
@login_required
|
@login_required
|
||||||
def index():
|
def index():
|
||||||
user = current_user
|
user = current_user
|
||||||
return render_template('admin/index.html', user=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
|
@login_required
|
||||||
def welcome():
|
def welcome():
|
||||||
return render_template('admin/console/console.html')
|
return render_template('admin/console/console.html')
|
||||||
|
|||||||
@@ -7,16 +7,20 @@ from applications.common.utils.validate import check_data
|
|||||||
from applications.models import DeptSchema
|
from applications.models import DeptSchema
|
||||||
from applications.common.admin import dept_curd as dept_curd
|
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)
|
@authorize("admin:dept:main", log=True)
|
||||||
def main():
|
def main():
|
||||||
return render_template('admin/dept/main.html')
|
return render_template('admin/dept/main.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.get('/data')
|
@dept_bp.get('/data')
|
||||||
@authorize("admin:dept:main", log=True)
|
@authorize("admin:dept:main", log=True)
|
||||||
def data():
|
def data():
|
||||||
power_data = dept_curd.get_dept_dict()
|
power_data = dept_curd.get_dept_dict()
|
||||||
@@ -26,13 +30,13 @@ def data():
|
|||||||
return jsonify(res)
|
return jsonify(res)
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.get('/add')
|
@dept_bp.get('/add')
|
||||||
@authorize("admin:dept:add", log=True)
|
@authorize("admin:dept:add", log=True)
|
||||||
def add():
|
def add():
|
||||||
return render_template('admin/dept/add.html')
|
return render_template('admin/dept/add.html')
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.get('/tree')
|
@dept_bp.get('/tree')
|
||||||
@authorize("admin:dept:main", log=True)
|
@authorize("admin:dept:main", log=True)
|
||||||
def tree():
|
def tree():
|
||||||
power_data = dept_curd.get_dept_dict()
|
power_data = dept_curd.get_dept_dict()
|
||||||
@@ -44,7 +48,7 @@ def tree():
|
|||||||
return jsonify(res)
|
return jsonify(res)
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.post('/save')
|
@dept_bp.post('/save')
|
||||||
@authorize("admin:dept:add", log=True)
|
@authorize("admin:dept:add", log=True)
|
||||||
def save():
|
def save():
|
||||||
req = request.json
|
req = request.json
|
||||||
@@ -53,7 +57,7 @@ def save():
|
|||||||
return success_api(msg="成功")
|
return success_api(msg="成功")
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.get('/edit')
|
@dept_bp.get('/edit')
|
||||||
@authorize("admin:dept:edit", log=True)
|
@authorize("admin:dept:edit", log=True)
|
||||||
def edit():
|
def edit():
|
||||||
_id = request.args.get("deptId")
|
_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)
|
@authorize("admin:dept:edit", log=True)
|
||||||
def enable():
|
def enable():
|
||||||
_id = request.json.get('deptId')
|
_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)
|
@authorize("admin:dept:edit", log=True)
|
||||||
def dis_enable():
|
def dis_enable():
|
||||||
_id = request.json.get('deptId')
|
_id = request.json.get('deptId')
|
||||||
@@ -87,7 +91,7 @@ def dis_enable():
|
|||||||
return fail_api(msg="数据错误")
|
return fail_api(msg="数据错误")
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.put('/update')
|
@dept_bp.put('/update')
|
||||||
@authorize("admin:dept:edit", log=True)
|
@authorize("admin:dept:edit", log=True)
|
||||||
def update():
|
def update():
|
||||||
req = request.json
|
req = request.json
|
||||||
@@ -98,7 +102,7 @@ def update():
|
|||||||
return success_api(msg="更新成功")
|
return success_api(msg="更新成功")
|
||||||
|
|
||||||
|
|
||||||
@admin_dept.delete('/remove/<int:_id>')
|
@dept_bp.delete('/remove/<int:_id>')
|
||||||
@authorize("admin:dept:remove", log=True)
|
@authorize("admin:dept:remove", log=True)
|
||||||
def remove(_id):
|
def remove(_id):
|
||||||
res = dept_curd.remove_dept(_id)
|
res = dept_curd.remove_dept(_id)
|
||||||
@@ -5,7 +5,7 @@ index_bp = Blueprint('Index', __name__, url_prefix='/')
|
|||||||
from . import index
|
from . import index
|
||||||
|
|
||||||
|
|
||||||
def init_index_views(app):
|
def register_index_views(app):
|
||||||
"""
|
"""
|
||||||
初始化蓝图
|
初始化蓝图
|
||||||
|
|
||||||
|
|||||||
@@ -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="注销成功")
|
||||||
@@ -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)
|
||||||
@@ -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)
|
||||||
+1
-1
@@ -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 (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 (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 (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 (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 (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);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user