From 8a477d5d690bb0ee57e2ce5144dd1a23f82b2588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=96=E5=85=AE=E5=86=89?= <15550273+wang-shengfa-11@user.noreply.gitee.com> Date: Fri, 10 Oct 2025 10:57:33 +0800 Subject: [PATCH] =?UTF-8?q?v2.1=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B9=B6=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=9F=BA=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/default-avatar.png | Bin 0 -> 2204 bytes .../wsf/mathapp/controller/SceneManager.java | 32 +++-- .../wsf/mathapp/view/LevelSelectionView.java | 8 +- .../com/wsf/mathapp/view/MainMenuView.java | 10 +- .../java/com/wsf/mathapp/view/ResultView.java | 2 +- .../com/ybw/mathapp/LoginAndRegister.java | 132 ------------------ 6 files changed, 36 insertions(+), 148 deletions(-) create mode 100644 images/default-avatar.png delete mode 100644 src/main/java/com/ybw/mathapp/LoginAndRegister.java diff --git a/images/default-avatar.png b/images/default-avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..e7fe7f48ec60ab024aeb904a5747326dad994e82 GIT binary patch literal 2204 zcmchXc|4R`7{|~1&Ss6tk|hygT>YrQpkNbPibKd9kp65O1`JVH94)PRv1r+UV z*V+OI0$>gL0Hh17r-l0M2Ef4q%m)BS0VviFU{MbZ0UD?QfZ;#@gT5ijHx4{C%Hd$9 zeMulP2q=!e%wT4aFY{L&vjvL)Wz|{-tYkJ+lfM3>tJtcQ@GKEr$MRUxX9h&8B9U8w zCrI6Og0T1FNPC{hG4gu%dA3=St*28uw( z0hWlHIhSmWS90MS*N4SfSclF@u~i^WSQ zOD$L1&}{A2thL|dym`ykZH(=nUf#QXeEs}`g7<~&4?Pf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=Le2m{HJeoO~dsp@rPz!x7%c@AOSBl&gT}RBh%Z)>NkPw{qppoOSQt zS+>`k_lA9>Zd9i$%6?4K|6*%qg34sV}kU47EP!PX0PJ9bsd z@|V=QdRC_z&8Aiq{Ul2pe374?Un0E!F~Wr&yQxUK?1Cz7d{F}l9#KZKKusHYGQA_c z;X#@YUp?GHY74T+;*j1C%`qN+5Tm}kA button.setStyle(String.format( "-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " + - "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);", + "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);", hoverColor ))); button.setOnMouseExited(e -> button.setStyle(String.format( "-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " + - "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", + "-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);", color ))); return button; diff --git a/src/main/java/com/wsf/mathapp/view/MainMenuView.java b/src/main/java/com/wsf/mathapp/view/MainMenuView.java index 2734eee..8953009 100644 --- a/src/main/java/com/wsf/mathapp/view/MainMenuView.java +++ b/src/main/java/com/wsf/mathapp/view/MainMenuView.java @@ -69,7 +69,7 @@ public class MainMenuView { avatarCircle.setStrokeWidth(2); // 添加阴影效果 - avatarCircle.setStyle("-fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); + avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);"); // 添加首字母文本 avatarText = new Text(getFirstLetter()); @@ -230,8 +230,12 @@ public class MainMenuView { } // 调用修改密码的后端逻辑 - ChangePassword.changePassword(currentUsername, confirmPwd); - showAlert("成功", "密码修改成功!"); + if(!ChangePassword.changePassword(currentUsername, confirmPwd)){ + showAlert("错误", "密码修改失败"); + } + else{ + showAlert("成功", "密码修改成功!"); + } } return null; }); diff --git a/src/main/java/com/wsf/mathapp/view/ResultView.java b/src/main/java/com/wsf/mathapp/view/ResultView.java index a1bb0c8..5276044 100644 --- a/src/main/java/com/wsf/mathapp/view/ResultView.java +++ b/src/main/java/com/wsf/mathapp/view/ResultView.java @@ -95,7 +95,7 @@ public class ResultView { private Image createTextAvatar() { // 创建一个简单的文本头像(使用首字母) - String firstLetter = currentUsername.length() > 0 ? + String firstLetter = !currentUsername.isEmpty() ? currentUsername.substring(0, 1).toUpperCase() : "U"; // 这里可以创建一个包含文本的图像,但为了简单起见,我们使用CSS样式 diff --git a/src/main/java/com/ybw/mathapp/LoginAndRegister.java b/src/main/java/com/ybw/mathapp/LoginAndRegister.java deleted file mode 100644 index d71d548..0000000 --- a/src/main/java/com/ybw/mathapp/LoginAndRegister.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.ybw.mathapp; - -// UserService.java -import com.ybw.mathapp.entity.User; -import com.ybw.mathapp.service.EmailService; -import com.ybw.mathapp.util.LoginFileUtils; -import java.util.Scanner; -import java.util.regex.Pattern; - -public class LoginAndRegister { - private static Scanner scanner = new Scanner(System.in); - - // UserService.java 中的注册方法更新 - public static boolean register() { - System.out.println("\n=== 用户注册 ==="); - - // 输入邮箱 - System.out.print("请输入邮箱地址: "); - String email = scanner.nextLine().trim(); - - if (!isValidEmail(email)) { - return false; - } - - if (LoginFileUtils.isEmailRegistered(email)) { - System.out.println("该邮箱已注册,请直接登录!"); - return false; - } - - // 发送、验证验证码 - if (!sendAndVerifyCode(email)) { - return false; - } - - // 设置密码(其余代码保持不变) - System.out.print("请输入密码: "); - String password1 = scanner.nextLine(); - System.out.print("请再次输入密码: "); - String password2 = scanner.nextLine(); - if(!isVaildPassword(password1, password2)) { - return false; - } - - User user = new User(email, password1); - LoginFileUtils.saveUser(user); - System.out.println("注册成功!您可以使用邮箱和密码登录了。"); - return true; - } - - // 登录流程 - public static boolean login() { - System.out.println("\n=== 用户登录 ==="); - - System.out.print("请输入邮箱: "); - String email = scanner.nextLine().trim(); - - System.out.print("请输入密码: "); - String password = scanner.nextLine(); - - if (LoginFileUtils.validateUser(email, password)) { - System.out.println("登录成功!欢迎回来," + email); - return true; - } else { - System.out.println("邮箱或密码错误!"); - return false; - } - } - - // - /** - * 邮箱格式验证 - * @param email 待验证的邮箱地址 - * @return true表示邮箱格式正确,false表示邮箱格式错误 - */ - private static boolean isValidEmail(String email) { - if (email.isEmpty()) { - System.out.println("邮箱地址不能为空!"); - return false; - } - if (!(email.contains("@") && email.contains("."))) { - System.out.println("邮箱格式不正确!"); - return false; - } - return true; - } - - /** - * 密码格式验证 - * @param password1 第一次输入的密码 - * @param password2 第二次输入的密码 - * @return true表示符合要求,false表示不符合 - */ - public static boolean isVaildPassword(String password1, String password2) { - if (password1 == null || password1.length() < 6 || password1.length() > 10) { - return false; - } - - // 使用正则表达式验证:长度6-10,只包含字母数字,且包含大小写字母和数字 - String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,10}$"; - if (!Pattern.matches(regex, password1)) { - return false; - } - - System.out.print("请再次输入密码: "); - if (!password1.equals(password2)) { - System.out.println("两次输入的密码不一致!"); - return false; - } - return true; - } - - public static boolean sendAndVerifyCode(String email) { - // 发送真实邮件验证码 - String verificationCode = EmailService.generateVerificationCode(); - System.out.println("正在发送验证码邮件,请稍候..."); - - if (!EmailService.sendVerificationCode(email, verificationCode)) { - System.out.println("发送验证码失败,请检查邮箱配置或稍后重试!"); - return false; - } - - // 验证验证码 - System.out.print("请输入收到的验证码: "); - String inputCode = scanner.nextLine().trim(); - - if (!EmailService.verifyCode(email, inputCode)) { - System.out.println("验证码错误或已过期!"); - return false; - } - return true; - } -}