From 875705f067fa9446531db51192ea5fb1d9bc2c86 Mon Sep 17 00:00:00 2001 From: smallbailangui Date: Tue, 7 Oct 2025 18:53:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mathgenerator/service/UserService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathgenerator/service/UserService.java b/src/main/java/com/mathgenerator/service/UserService.java index 05b2409..f154390 100644 --- a/src/main/java/com/mathgenerator/service/UserService.java +++ b/src/main/java/com/mathgenerator/service/UserService.java @@ -1,6 +1,7 @@ package com.mathgenerator.service; import com.google.gson.Gson; +import java.util.Objects; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.mathgenerator.model.User; @@ -81,10 +82,22 @@ public class UserService { * @return 成功返回true, 否则返回false */ public boolean register(String username, String email, String password) { - if (userDatabase.containsKey(username) || - userDatabase.values().stream().anyMatch(u -> u.email().equals(email))) { + // 1. 基础校验:防止 null 或空白输入 + if (username == null || email == null || password == null || + username.trim().isEmpty() || email.trim().isEmpty() || password.trim().isEmpty()) { + return false; + } + + // 2. 检查用户名或邮箱是否已存在(使用 Objects.equals 安全比较) + boolean usernameExists = userDatabase.containsKey(username); + boolean emailExists = userDatabase.values().stream() + .anyMatch(u -> Objects.equals(u.email(), email)); + + if (usernameExists || emailExists) { return false; // 用户名或邮箱已存在 } + + // 3. 创建新用户并保存 User newUser = new User(username, email, password); userDatabase.put(username, newUser); saveUsers(); -- 2.34.1 From 933e564990e351deb97fd69fca5364911a3dea3c Mon Sep 17 00:00:00 2001 From: smallbailangui Date: Tue, 7 Oct 2025 19:22:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9Ejavafx=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index a0c33b8..8fdb633 100644 --- a/pom.xml +++ b/pom.xml @@ -9,49 +9,76 @@ 1.0.0 + 17 17 UTF-8 + + + 21.0.8 + com.google.code.gson gson 2.10.1 + + + + org.openjfx + javafx-controls + ${javafx.version} + + + + + org.openjfx + javafx-fxml + ${javafx.version} + + + + + org.openjfx + javafx-graphics + ${javafx.version} + - + org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - default-jar - none - - + maven-compiler-plugin + 3.11.0 + + 17 + 17 + - + + maven-assembly-plugin 3.6.0 + com.mathgenerator.Application jar-with-dependencies - mathgenerator - false + mathgenerator + false + single @@ -65,5 +92,4 @@ - \ No newline at end of file -- 2.34.1