update
This commit is contained in:
parent
7507de7ed2
commit
d0fc6a4c08
|
|
@ -60,7 +60,7 @@ app.config['SESSION_COOKIE_NAME'] = "MW_VER_1"
|
|||
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=31)
|
||||
|
||||
# db的配置
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = mw.getSqitePrefix()+config.SQLITE_PATH # 使用 SQLite 数据库
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = mw.getSqitePrefix()+config.SQLITE_PATH+"?timeout=20" # 使用 SQLite 数据库
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
|
||||
# 缓存配置
|
||||
|
|
|
|||
|
|
@ -49,28 +49,70 @@ def code():
|
|||
|
||||
@blueprint.route('/login')
|
||||
def login():
|
||||
signout = request.args.get('signout', '')
|
||||
if signout == 'True':
|
||||
session.clear()
|
||||
session['login'] = False
|
||||
session['overdue'] = 0
|
||||
return render_template('default/login.html')
|
||||
|
||||
# 检查是否登录
|
||||
@blueprint.route('/check_login',methods=['GET','POST'])
|
||||
def check_login():
|
||||
if isLogined():
|
||||
return "true"
|
||||
return "false"
|
||||
return mw.returnData(True,'已登录')
|
||||
return mw.returnData(False,'未登录')
|
||||
|
||||
# 执行登录操作
|
||||
@blueprint.route('/do_login', endpoint='do_login', methods=['POST'])
|
||||
def do_login():
|
||||
|
||||
username = request.form.get('username', '').strip()
|
||||
password = request.form.get('password', '').strip()
|
||||
code = request.form.get('code', '').strip()
|
||||
|
||||
login_cache_count = 5
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
|
||||
if 'code' in session:
|
||||
if session['code'] != mw.md5(code):
|
||||
return mw.returnData(False, code_msg)
|
||||
if login_cache_limit == None:
|
||||
login_cache_limit = 1
|
||||
else:
|
||||
login_cache_limit = int(login_cache_limit) + 1
|
||||
|
||||
print(username, password, code)
|
||||
print(cache,session)
|
||||
if login_cache_limit >= login_cache_count:
|
||||
model.setOption('admin_close', 'yes')
|
||||
return mw.returnJson(False, '面板已经关闭!')
|
||||
|
||||
return mw.returnData(1, '登录成功,正在跳转...')
|
||||
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
login_err_msg = mw.getInfo("验证码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit)))
|
||||
mw.writeLog('用户登录', login_err_msg)
|
||||
return mw.returnData(False, login_err_msg)
|
||||
|
||||
info = model.getUserByName(username)
|
||||
password = mw.md5(password)
|
||||
|
||||
if info['name'] != username or info['password'] != password:
|
||||
msg = "<a style='color: red'>密码错误</a>,帐号:{1},密码:{2},登录IP:{3}", (('****', '******', request.remote_addr))
|
||||
|
||||
if login_cache_limit == None:
|
||||
login_cache_limit = 1
|
||||
else:
|
||||
login_cache_limit = int(login_cache_limit) + 1
|
||||
|
||||
if login_cache_limit >= login_cache_count:
|
||||
model.setOption('admin_close', 'yes')
|
||||
return mw.returnData(False, '面板已经关闭!')
|
||||
|
||||
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
|
||||
login_cache_limit = cache.get('login_cache_limit')
|
||||
mw.writeLog('用户登录', mw.getInfo(msg))
|
||||
return mw.returnData(-1, mw.getInfo("用户名或密码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit))))
|
||||
|
||||
|
||||
session['login'] = True
|
||||
session['username'] = info['name']
|
||||
session['overdue'] = int(time.time()) + 7 * 24 * 60 * 60
|
||||
|
||||
return mw.returnJson(1, '登录成功,正在跳转...')
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ from flask import Blueprint, render_template
|
|||
from flask import request
|
||||
|
||||
from admin.user_login_check import panel_login_required
|
||||
|
||||
from admin import model
|
||||
from admin.model import db, Logs
|
||||
|
||||
import core.mw as mw
|
||||
|
|
@ -59,9 +61,8 @@ def get_log_list():
|
|||
@blueprint.route('/del_panel_logs', endpoint='del_panel_logs', methods=['POST'])
|
||||
@panel_login_required
|
||||
def del_panel_logs():
|
||||
db.session.query(Logs).filter(Logs.id > 0).delete()
|
||||
# db.session.execute('truncate table logs;')
|
||||
db.session.commit()
|
||||
model.clearLog()
|
||||
# mw.M('logs').dbPos(mw.getPanelDataDir(),'panel').where('id>?', (0,)).delete()
|
||||
mw.writeLog('面板设置', '面板操作日志已清空!')
|
||||
return mw.returnData(True, '面板操作日志已清空!')
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
from .initdb import *
|
||||
|
||||
from .logs import addLog
|
||||
from .logs import addLog,clearLog
|
||||
|
||||
from .option import getOption,getOptionByJson,setOption
|
||||
from .option import setOption
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ SCHEMA_VERSION = 1
|
|||
db = SQLAlchemy(
|
||||
engine_options={
|
||||
'pool_size': config.CONFIG_DATABASE_CONNECTION_POOL_SIZE,
|
||||
'max_overflow': config.CONFIG_DATABASE_CONNECTION_MAX_OVERFLOW
|
||||
'max_overflow': config.CONFIG_DATABASE_CONNECTION_MAX_OVERFLOW,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@ def formatDate(format="%Y-%m-%d %H:%M:%S", times=None):
|
|||
time_local = time.localtime(times)
|
||||
return time.strftime(format, time_local)
|
||||
|
||||
def clearLog():
|
||||
try:
|
||||
# from sqlalchemy import text
|
||||
# db.session.execute(text("DELETE FROM logs where id>1"))
|
||||
db.session.query(Logs).filter(Logs.id > 0).delete(synchronize_session=False)
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
db.session.commit()
|
||||
finally:
|
||||
db.session.close()
|
||||
return True
|
||||
|
||||
def addLog(type, log,
|
||||
uid: int | None = 1
|
||||
) -> str:
|
||||
|
|
@ -38,4 +50,5 @@ def addLog(type, log,
|
|||
add_time=add_time)
|
||||
db.session.add(add_logs)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
return True
|
||||
|
|
@ -48,6 +48,7 @@ def addTask(
|
|||
add_time=add_time)
|
||||
db.session.add(add_data)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
return True
|
||||
|
||||
def getTaskFirstByRun() -> None:
|
||||
|
|
|
|||
|
|
@ -20,10 +20,14 @@ def init_option():
|
|||
model.setOption('recycle_bin', 'open')
|
||||
model.setOption('template', 'default')
|
||||
|
||||
# 后台面板是否关闭
|
||||
model.setOption('admin_close', 'no')
|
||||
# 调式模式,默认关闭
|
||||
model.setOption('debug', 'close')
|
||||
|
||||
|
||||
|
||||
|
||||
# 开启后台任务
|
||||
# model.setOption('run_bg_task', 'close')
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from version import APP_VERSION, APP_RELEASE, APP_REVISION, APP_SUFFIX
|
|||
DEBUG = False
|
||||
|
||||
# 配置数据库连接池大小。将其设置为0将删除任何限制
|
||||
CONFIG_DATABASE_CONNECTION_POOL_SIZE = 5
|
||||
CONFIG_DATABASE_CONNECTION_POOL_SIZE = 1
|
||||
# 允许溢出超过连接池大小的连接数
|
||||
CONFIG_DATABASE_CONNECTION_MAX_OVERFLOW = 100
|
||||
|
||||
|
|
|
|||
|
|
@ -1611,8 +1611,10 @@ function backMyComputer() {
|
|||
//检查登陆状态
|
||||
function check_login(){
|
||||
$.post('/check_login',{},function(rdata){
|
||||
if(rdata === true) return;
|
||||
});
|
||||
if(!rdata.status){
|
||||
location.reload();
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
//登陆跳转
|
||||
|
|
|
|||
Loading…
Reference in New Issue