Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/web/admin/dashboard/__init__.py

77 lines
2.3 KiB

7 months ago
# coding:utf-8
7 months ago
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
6 months ago
import io
import time
7 months ago
7 months ago
from flask import Blueprint, render_template
6 months ago
from flask import make_response
from flask import Response
7 months ago
from flask import request,g
7 months ago
6 months ago
from admin.common import isLogined
from admin.user_login_check import panel_login_required
from admin import cache,session
from admin import model
7 months ago
import core.mw as mw
6 months ago
7 months ago
blueprint = Blueprint('dashboard', __name__, url_prefix='/', template_folder='../../templates')
7 months ago
@blueprint.route('/')
6 months ago
@panel_login_required
7 months ago
def index():
7 months ago
return render_template('default/index.html')
7 months ago
# ---------------------------------------------------------------------------------
# 定义登录入口相关方法
# ---------------------------------------------------------------------------------
7 months ago
6 months ago
# 验证码
@blueprint.route('/code')
def code():
import utils.vilidate as vilidate
vie = vilidate.vieCode()
codeImage = vie.GetCodeImage(80, 4)
out = io.BytesIO()
codeImage[0].save(out, "png")
session['code'] = mw.md5(''.join(codeImage[1]).lower())
img = Response(out.getvalue(), headers={'Content-Type': 'image/png'})
return make_response(img)
7 months ago
@blueprint.route('/login')
def login():
7 months ago
return render_template('default/login.html')
7 months ago
7 months ago
# 检查是否登录
7 months ago
@blueprint.route('/check_login',methods=['GET','POST'])
7 months ago
def check_login():
6 months ago
if isLogined():
return "true"
return "false"
7 months ago
# 执行登录操作
@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()
6 months ago
if 'code' in session:
if session['code'] != mw.md5(code):
return mw.returnData(False, code_msg)
print(username, password, code)
print(cache,session)
7 months ago
6 months ago
return mw.returnData(1, '登录成功,正在跳转...')