From 875203f3b5223e00844c23c8016e507a9034c16a Mon Sep 17 00:00:00 2001 From: Zecyel Date: Sat, 20 Nov 2021 17:26:52 +0800 Subject: [PATCH 1/2] fix bug * inf --- README.md | 59 ++++++++++++++++++++++++++-------------------------- deco.py | 12 +++++------ main.py | 5 ++++- res.py | 3 +++ tokenlib.py | 13 +++++++++--- user.py | 7 ++++++- volunteer.py | 3 +++ 7 files changed, 61 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 7d35426..65026e5 100644 --- a/README.md +++ b/README.md @@ -6,33 +6,32 @@ ----- - 1. 启用virtualenv开发环境 - ``` - Windows: - - py -3 -m venv venv - venv\Scripts\activate - - Linux: - - source venv/bin/activate - ``` - 2. 安装Flask - ``` - pip install flask - pip install flask_cors - ``` - Postscript: 如果上一条指令不能使用,请使用下面这一条 - ``` - pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn flask - ``` - 3. 安装MySQL - 4. 安装MySQLdb - ``` - pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn pymysql - ``` - 5. MySQL初始化,详见`sql.sql` - 6. 启动程序 - ``` - python main.py - ``` \ No newline at end of file +1. 启用virtualenv开发环境 +``` +Windows: + +py -3 -m venv venv +venv\Scripts\activate + +Linux: + +source venv/bin/activate +``` +2. 安装Flask +``` +pip install flask +pip install flask_cors +``` +Postscript: 如果上一条指令不能使用,请使用下面这一条 +``` +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn flask +``` +3. 安装MySQL +4. 安装pymysql +``` +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn pymysql +``` +5. 启动程序 +``` +python main.py +``` \ No newline at end of file diff --git a/deco.py b/deco.py index 8015574..72d89de 100644 --- a/deco.py +++ b/deco.py @@ -25,14 +25,14 @@ def Deco(func): @wraps(func) def wrapper(*args,**kwargs): # tmp,sys.stdout=sys.stdout,open("logs/debug.log","w+") # 重定向到文件输出 # - print("Entering Function->%s:"%func.__name__) + # print("Entering Function->%s:"%func.__name__) global postdata, tkst, tkdata # 重要!! try: # 为了防止空POST出锅 postdata=json.loads(request.get_data().decode("utf-8")) - print("Postdata:",postdata) # 加载到的POST数据 + # print("Postdata:",postdata) # 加载到的POST数据 except: postdata="" - print("No Postdata loaded.") + # print("No Postdata loaded.") if not "NoToken" in func.__name__: # 为了判断是否需要Token验证 @@ -40,7 +40,7 @@ def Deco(func): # 所以请在不用Token的函数名后面加上"_NoToken" try: # 获取Token tkst, tkdata=TK.readToken(request.headers.get("Authorization")) - print("Loading Token:",tkst, tkdata) + # print("Loading Token:",tkst, tkdata) if tkst==TK.EXPIRED: return json.dumps({'type':'ERROR', 'message':"token过期,请重新登陆"}) elif tkst==TK.BAD: @@ -53,7 +53,7 @@ def Deco(func): try: r=func(*args,**kwargs) - print("result->",r) # 函数返回的JSON + # print("result->",r) # 函数返回的JSON # 如果想做错误输出的话加在这里 # sys.stdout=tmp # 重新回到控制台输出 # return json.dumps(r) @@ -62,4 +62,4 @@ def Deco(func): # 出现这种情况说明代码锅了或者前端接口错了 # sys.stdout=tmp # 重新回到控制台输出 # return json.dumps({'type':'ERROR','message':'未知错误'}) - return wrapper \ No newline at end of file + return wrapper diff --git a/main.py b/main.py index 4e2767a..309534e 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ from flask import Flask,make_response,request from flask_cors import CORS +# from flask_script import Manager import database from user import User from _class import Class @@ -10,7 +11,7 @@ from report import Report # Flask init app = Flask(__name__) -app.debug = True # 仅在测试环境打开! +app.debug = False # 仅在测试环境打开! app.config["SECRET_KEY"] = "PaSsw0rD@1234!@#$" CORS(app, supports_credentials=True) # 允许跨域 @@ -26,5 +27,7 @@ app.register_blueprint(Report) def main(): return "" +# manager = Manager(app) if __name__ == '__main__': + # manager.run(host='0.0.0.0', port=5000) app.run(host='0.0.0.0', port=5000) diff --git a/res.py b/res.py index bb93615..577fd61 100644 --- a/res.py +++ b/res.py @@ -19,3 +19,6 @@ def checkPermission(cls,pms,stu): # 判断一个用户是否有权限管理该 # 教师、义管会、系统能管理所有学生 # 班级编号为6位:202001,学号为8位:20200100~20200199 return pms in [PMS_CLASS,PMS_TEACHER,PMS_SYSTEM] or(pms==PMS_CLASS and stu>=cls*100 and stu', methods = ['GET', 'OPTIONS']) @@ -110,6 +111,8 @@ def createVolunteer(): # 大概可以了 print("count check failed.") return {"type":"ERROR", "message":"最大人数不符合要求:义工人数永远无法报满"} print(666) + if json_data()["inside"]<0 or json_data()["outside"]<0 or json_data()["large"]<0: + return {"type":"ERROR", "message":"义工时间不能为负数"} # 创建一条总的记录 OP.insert("volName,volDate,volTime,stuMax,nowStuCount,description,status," +"volTimeInside,volTimeOutside,volTimeLarge,holderId", -- Gitee From b8c7cd80bb974bdda738be5d9f52df36a165d5d0 Mon Sep 17 00:00:00 2001 From: Zecyel Date: Mon, 22 Nov 2021 16:55:57 +0800 Subject: [PATCH 2/2] version that suits electron:1.2.2 and web:1.1.3 --- report.py | 6 ++++-- res.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/report.py b/report.py index 1365bd1..353574b 100644 --- a/report.py +++ b/report.py @@ -3,6 +3,7 @@ import json from deco import * from res import * import oppressor as OP +import datetime Report = Blueprint('report', __name__) @@ -11,6 +12,7 @@ Report = Blueprint('report', __name__) def submitReport_NoToken(): report = json_data().get('report') f = open('./report.log', 'a+') - f.write(report + '\n') + # 2021.11.22 10.40 Modified by nekomoyi + f.write('[' + datetime.datetime.now() + '] ' + report + '\n') f.close() - return {"type":"SUCCESS", "message":"提交成功"} \ No newline at end of file + return {"type":"SUCCESS", "message":"提交成功"} diff --git a/res.py b/res.py index 577fd61..1c826a3 100644 --- a/res.py +++ b/res.py @@ -20,5 +20,5 @@ def checkPermission(cls,pms,stu): # 判断一个用户是否有权限管理该 # 班级编号为6位:202001,学号为8位:20200100~20200199 return pms in [PMS_CLASS,PMS_TEACHER,PMS_SYSTEM] or(pms==PMS_CLASS and stu>=cls*100 and stu