更新依赖,使用flask新路由定义方法

This commit is contained in:
mkg
2021-06-12 12:59:56 +08:00
parent f274e060f4
commit 48633729fb
11 changed files with 155 additions and 153 deletions
+44 -40
View File
@@ -9,7 +9,7 @@ admin_index = Blueprint('adminIndex', __name__, url_prefix='/admin')
# 首页
@admin_index.route('/')
@admin_index.get('/')
@login_required
def index():
user = current_user
@@ -17,14 +17,14 @@ def index():
# 渲染配置
@admin_index.route('/config')
@admin_index.get('/config')
@login_required
def config():
return index_curd.get_render_config()
# 获取验证码
@admin_index.route('/getCaptcha', methods=["GET"])
@admin_index.get('/getCaptcha')
def getCaptcha():
resp, code = index_curd.get_captcha()
session["code"] = code
@@ -32,48 +32,52 @@ def getCaptcha():
# 登录
@admin_index.route('/login', methods=['GET', 'POST'])
@admin_index.get('/login')
def login():
if request.method == '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="用户名或密码错误")
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.route('/logout', methods=['GET', 'POST'])
@admin_index.post('/logout')
@login_required
def logout():
logout_user()
@@ -82,7 +86,7 @@ def logout():
# 菜单
@admin_index.route('/menu')
@admin_index.get('/menu')
@login_required
def menu():
menu_tree = index_curd.make_menu_tree()
@@ -90,7 +94,7 @@ def menu():
# 控制台页面
@admin_index.route('/welcome')
@admin_index.get('/welcome')
@login_required
def welcome():
return render_template('admin/console/console.html')