|
|
@ -49,28 +49,70 @@ def code(): |
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/login') |
|
|
|
@blueprint.route('/login') |
|
|
|
def 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') |
|
|
|
return render_template('default/login.html') |
|
|
|
|
|
|
|
|
|
|
|
# 检查是否登录 |
|
|
|
# 检查是否登录 |
|
|
|
@blueprint.route('/check_login',methods=['GET','POST']) |
|
|
|
@blueprint.route('/check_login',methods=['GET','POST']) |
|
|
|
def check_login(): |
|
|
|
def check_login(): |
|
|
|
if isLogined(): |
|
|
|
if isLogined(): |
|
|
|
return "true" |
|
|
|
return mw.returnData(True,'已登录') |
|
|
|
return "false" |
|
|
|
return mw.returnData(False,'未登录') |
|
|
|
|
|
|
|
|
|
|
|
# 执行登录操作 |
|
|
|
# 执行登录操作 |
|
|
|
@blueprint.route('/do_login', endpoint='do_login', methods=['POST']) |
|
|
|
@blueprint.route('/do_login', endpoint='do_login', methods=['POST']) |
|
|
|
def do_login(): |
|
|
|
def do_login(): |
|
|
|
|
|
|
|
|
|
|
|
username = request.form.get('username', '').strip() |
|
|
|
username = request.form.get('username', '').strip() |
|
|
|
password = request.form.get('password', '').strip() |
|
|
|
password = request.form.get('password', '').strip() |
|
|
|
code = request.form.get('code', '').strip() |
|
|
|
code = request.form.get('code', '').strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
login_cache_count = 5 |
|
|
|
|
|
|
|
login_cache_limit = cache.get('login_cache_limit') |
|
|
|
|
|
|
|
|
|
|
|
if 'code' in session: |
|
|
|
if 'code' in session: |
|
|
|
if session['code'] != mw.md5(code): |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if login_cache_limit >= login_cache_count: |
|
|
|
|
|
|
|
model.setOption('admin_close', 'yes') |
|
|
|
|
|
|
|
return mw.returnJson(False, '面板已经关闭!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(username, password, code) |
|
|
|
session['login'] = True |
|
|
|
print(cache,session) |
|
|
|
session['username'] = info['name'] |
|
|
|
|
|
|
|
session['overdue'] = int(time.time()) + 7 * 24 * 60 * 60 |
|
|
|
|
|
|
|
|
|
|
|
return mw.returnData(1, '登录成功,正在跳转...') |
|
|
|
return mw.returnJson(1, '登录成功,正在跳转...') |
|
|
|