后台查询Asin文档更新
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@ import os
|
||||
import re
|
||||
|
||||
import requests
|
||||
from flask import Blueprint, request, jsonify, session
|
||||
from flask import Blueprint, request, jsonify, session, current_app
|
||||
|
||||
import pymysql
|
||||
from werkzeug.security import generate_password_hash
|
||||
@@ -461,7 +461,10 @@ def get_admin_current_user_menus():
|
||||
@login_required
|
||||
def admin_logout():
|
||||
session.clear()
|
||||
return jsonify({'success': True, 'msg': '退出成功', 'redirect': '/login'})
|
||||
response = jsonify({'success': True, 'msg': '退出成功', 'redirect': '/login?logout=1'})
|
||||
response.delete_cookie(current_app.config.get('SESSION_COOKIE_NAME', 'session'))
|
||||
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
|
||||
return response
|
||||
|
||||
|
||||
# ---------- 用户管理 ----------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
认证蓝图:登录、登出、登录状态校验
|
||||
"""
|
||||
from flask import Blueprint, request, redirect, url_for, session, jsonify
|
||||
from flask import Blueprint, request, redirect, url_for, session, jsonify, make_response, current_app
|
||||
from werkzeug.security import check_password_hash
|
||||
|
||||
from utils.db import get_db
|
||||
@@ -13,14 +13,23 @@ auth = Blueprint('auth', __name__, url_prefix='')
|
||||
|
||||
@auth.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if session.get('user_id') and is_session_user_valid():
|
||||
force_relogin = request.args.get('logout') == '1' or request.args.get('switch') == '1'
|
||||
if request.method == 'GET' and force_relogin:
|
||||
session.clear()
|
||||
response = make_response(render_html('login.html'))
|
||||
response.delete_cookie(current_app.config.get('SESSION_COOKIE_NAME', 'session'))
|
||||
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
|
||||
return response
|
||||
if request.method == 'GET' and session.get('user_id') and is_session_user_valid():
|
||||
return redirect(url_for('main.admin_page'))
|
||||
if request.method == 'POST':
|
||||
session.clear()
|
||||
wants_json = request.is_json or request.headers.get('X-Requested-With') == 'XMLHttpRequest'
|
||||
data = request.get_json() if request.is_json else request.form
|
||||
username = (data.get('username') or '').strip()
|
||||
password = data.get('password') or ''
|
||||
if not username or not password:
|
||||
if request.is_json:
|
||||
if wants_json:
|
||||
return jsonify({'success': False, 'error': '请输入用户名和密码'})
|
||||
return render_html('login.html', error='请输入用户名和密码')
|
||||
try:
|
||||
@@ -36,14 +45,14 @@ def login():
|
||||
session.permanent = True
|
||||
session['user_id'] = row['id']
|
||||
session['username'] = username
|
||||
if request.is_json:
|
||||
if wants_json:
|
||||
return jsonify({'success': True, 'redirect': url_for('main.admin_page')})
|
||||
return redirect(url_for('main.admin_page'))
|
||||
except Exception as exc:
|
||||
if request.is_json:
|
||||
if wants_json:
|
||||
return jsonify({'success': False, 'error': str(exc)})
|
||||
return render_html('login.html', error='登录失败,请稍后重试')
|
||||
if request.is_json:
|
||||
if wants_json:
|
||||
return jsonify({'success': False, 'error': '用户名或密码错误'})
|
||||
return render_html('login.html', error='用户名或密码错误')
|
||||
return render_html('login.html')
|
||||
@@ -71,4 +80,7 @@ def api_auth_check():
|
||||
@auth.route('/logout')
|
||||
def logout():
|
||||
session.clear()
|
||||
return redirect(url_for('auth.login'))
|
||||
response = redirect(url_for('auth.login', logout='1'))
|
||||
response.delete_cookie(current_app.config.get('SESSION_COOKIE_NAME', 'session'))
|
||||
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
|
||||
return response
|
||||
|
||||
@@ -23,8 +23,8 @@ bucket_path = "nanri-image/"
|
||||
file_url_pre = f"https://{bucket}.oss-cn-hangzhou.aliyuncs.com/"
|
||||
|
||||
import os
|
||||
backend_java_base_url = os.environ.get('BACKEND_JAVA_BASE_URL', 'http://127.0.0.1:18080').rstrip('/')
|
||||
# backend_java_base_url = os.environ.get('BACKEND_JAVA_BASE_URL', 'http://8.136.19.173:18080').rstrip('/')
|
||||
# backend_java_base_url = os.environ.get('BACKEND_JAVA_BASE_URL', 'http://127.0.0.1:18080').rstrip('/')
|
||||
backend_java_base_url = os.environ.get('BACKEND_JAVA_BASE_URL', 'http://8.136.19.173:18080').rstrip('/')
|
||||
os.environ['OSS_ACCESS_KEY_ID'] = accessKeyId
|
||||
os.environ['OSS_ACCESS_KEY_SECRET'] = accessKeySecret
|
||||
os.environ['SECRET_KEY'] = "ddffc7c1d02121d9554d7b080b2511b6"
|
||||
|
||||
@@ -4162,10 +4162,10 @@
|
||||
alert(res.error || '退出失败');
|
||||
return;
|
||||
}
|
||||
window.location.href = res.redirect || '/login';
|
||||
window.location.replace(res.redirect || '/login?logout=1');
|
||||
})
|
||||
.catch(function () {
|
||||
window.location.href = '/logout';
|
||||
window.location.replace('/logout');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -118,6 +118,10 @@
|
||||
</div>
|
||||
<script>
|
||||
(function() {
|
||||
var params = new URLSearchParams(window.location.search || '');
|
||||
if (params.get('logout') === '1' || params.get('switch') === '1') {
|
||||
return;
|
||||
}
|
||||
fetch('/api/auth/check', { credentials: 'same-origin' })
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(res) {
|
||||
|
||||
Reference in New Issue
Block a user