1 Star 0 Fork 86

头秃的程序员/admin_sys

forked from jackfrued/admin_sys 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
"""
main.py -
Author: Hao
Date: 2021/9/9
"""
import flask
from flask import redirect, session, request, make_response
from flask_cors import CORS
import captcha
from utils import random_captcha_code
app = flask.Flask(__name__)
app.secret_key = '1Qaz2Wsx'
CORS(app)
@app.before_request
def check_login():
url = request.path
user_id = session.get('user_id')
if url == '/' and user_id is None:
return redirect('/static/lyear_pages_login.html')
@app.route('/')
def show_index():
return redirect('/static/index.html')
@app.route('/captcha')
def get_captcha_image():
cap = captcha.Captcha.instance() # type: captcha.Captcha
captcha_code = random_captcha_code()
session['captcha_code'] = captcha_code.lower()
cap_image_data = cap.generate(captcha_code)
resp = make_response(cap_image_data)
resp.headers['content-type'] = 'image/png'
return resp
@app.route('/login', methods=['POST', ])
def login():
params = request.json
captcha_from_user = params.get('captcha').lower()
captcha_from_sess = session.get('captcha_code')
if captcha_from_sess != captcha_from_user:
return {'code': 10001, 'message': '验证码错误'}
username = params.get('username')
password = params.get('password')
return {'code': 10000, 'message': '登录成功'}
if __name__ == '__main__':
app.run(port=8000, debug=True)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/bald-programmer233/admin_sys.git
git@gitee.com:bald-programmer233/admin_sys.git
bald-programmer233
admin_sys
admin_sys
master

搜索帮助