Skip to content

Commit

Permalink
feat: student numbers can only be digit
Browse files Browse the repository at this point in the history
  • Loading branch information
GamerNoTitle committed Dec 30, 2024
1 parent 5265bf4 commit 5e03e2d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ Execute-Step -StepName "编译 Flask 服务器组件" -StepScript {
--windows-icon-from-ico=ui/static/img/favicon.ico `
--windows-company-name=GamerNoTitle `
--windows-product-name="口算速算 MentalArithmeticApp" `
--windows-file-version=1.3 `
--windows-product-version=1.3 `
--windows-file-version=1.4 `
--windows-product-version=1.4 `
--lto=yes --assume-yes-for-downloads ui/app.py
}

Expand Down
23 changes: 20 additions & 3 deletions ui/route/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,12 @@ def teacher_add_students() -> Response:
):
body = {"success": False, "msg": "请填写完整的学生信息!"}
return jsonify(body)
# 验证学号是否为全数字
if not student.get("number").isdigit():
body = {
"success": False,
"msg": "学号必须为纯数字!"
}
# 验证学号是否在合法范围内
if (
int(student.get("number")) < 0
Expand Down Expand Up @@ -1114,7 +1120,13 @@ def teacher_add_students() -> Response:
for (
student
) in students: # 每个学生的结构为:[number, name, class_name, password]
if student[0] > 4294967295 or student[0] <= 0:
if not student[0].isdigit():
failed_students_list.append(
(student[1], f"学号 {student[0]} 不是数字。")
)
failed_count += 1
continue
if int(student[0]) > 4294967295 or int(student[0]) <= 0:
failed_students_list.append(
(student[1], f"学号 {student[0]} 不符合要求。")
)
Expand Down Expand Up @@ -1348,7 +1360,6 @@ def teacher_modify_student() -> Response:
]
):
body = {"success": False, "msg": "请填写完整的学生信息!"}
print(data, c_strlen(data.get("className")))
# 查询当前学生的信息
student_records = query_users_info_all(1, key="id", content=student_id)
if not student_records:
Expand All @@ -1375,7 +1386,13 @@ def teacher_modify_student() -> Response:
body = {"success": False, "msg": f'学生名字中的 "{char}" 字符不合法!'}
return jsonify(body)
student = student_records[0] # 获取查询到的学生记录

# 验证学号是否为纯数字
if not data.get("number").isdigit():
body = {
"success": False,
"msg": "学号必须为纯数字!"
}
return jsonify(body)
try:
# 验证学号是否在合法范围内
student_number = int(data.get("number"))
Expand Down
2 changes: 1 addition & 1 deletion ui/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def students_xlsx_parser(raw_data: bytes) -> list:
student_class = str(student_class)
if not all([number, name, student_class, password]):
break
results.append((int(number), name, student_class, password))
results.append((number, name, student_class, password))
except Exception as e:
print(f"第{row_idx}行:发生错误: {e}")
continue
Expand Down

0 comments on commit 5e03e2d

Please sign in to comment.