修改一些小bug,例如注册界面到登录界面再到注册界面时,上一次注册的数据还在 #5

Merged
ppy4sjqvf merged 1 commits from master into develop 4 months ago

@ -6,7 +6,7 @@ import javafx.stage.Stage;
public class SceneManager {
private final Stage primaryStage;
private final LoginView loginView;
private final RegisterView registerView;
private RegisterView registerView;
private final MainMenuView mainMenuView;
private final LevelSelectionView levelSelectionView;
private final QuestionCountView questionCountView;
@ -31,12 +31,14 @@ public class SceneManager {
public void showLoginView() {
System.out.println("切换到登录界面");
loginView.clearFields();
primaryStage.setScene(loginView.getScene());
primaryStage.show();
}
public void showRegisterView() {
System.out.println("切换到注册界面");
registerView.clearFields();
primaryStage.setScene(registerView.getScene());
primaryStage.show();
}

@ -15,6 +15,11 @@ public class LoginView {
private Scene scene;
private final SceneManager sceneManager;
// 将UI组件声明为类的成员变量
private TextField usernameOrEmailField;
private PasswordField passwordField;
private Label statusLabel;
public LoginView(SceneManager sceneManager) {
this.sceneManager = sceneManager;
createScene();
@ -32,12 +37,12 @@ public class LoginView {
subtitleLabel.setFont(Font.font(18));
// 修改提示文本
TextField usernameOrEmailField = new TextField();
usernameOrEmailField = new TextField();
usernameOrEmailField.setPromptText("请输入用户名或邮箱");
usernameOrEmailField.setMaxWidth(300);
usernameOrEmailField.setPrefHeight(40);
PasswordField passwordField = new PasswordField();
passwordField = new PasswordField();
passwordField.setPromptText("请输入密码");
passwordField.setMaxWidth(300);
passwordField.setPrefHeight(40);
@ -50,7 +55,7 @@ public class LoginView {
registerButton.setStyle("-fx-background-color: #2196F3; -fx-text-fill: white; -fx-font-size: 14px;");
registerButton.setPrefSize(300, 40);
Label statusLabel = new Label();
statusLabel = new Label();
loginButton.setOnAction(e -> {
String usernameOrEmail = usernameOrEmailField.getText().trim();
@ -97,6 +102,15 @@ public class LoginView {
scene = new Scene(root, 400, 500);
}
/**
*
*/
public void clearFields() {
usernameOrEmailField.clear();
passwordField.clear();
statusLabel.setText("");
}
private void showError(Label label, String message) {
label.setText(message);
label.setStyle("-fx-text-fill: red;");

@ -3,6 +3,7 @@ package com.wsf.mathapp.view;
import com.wsf.mathapp.controller.SceneManager;
import com.ybw.mathapp.util.ChangePassword;
import com.ybw.mathapp.util.Login;
import com.ybw.mathapp.util.Register;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
@ -187,7 +188,7 @@ public class MainMenuView {
oldPassword.setPrefWidth(200);
javafx.scene.control.PasswordField newPassword = new javafx.scene.control.PasswordField();
newPassword.setPromptText("请输入新密码");
newPassword.setPromptText("请输入新密码密码要6-10位包含大小写字母和数字");
newPassword.setPrefWidth(200);
javafx.scene.control.PasswordField confirmPassword = new javafx.scene.control.PasswordField();
@ -228,10 +229,14 @@ public class MainMenuView {
showAlert("错误", "两次输入的新密码不一致!");
return null;
}
if (!Register.isVaildPassword(newPwd)) {
showAlert("错误", "密码要6-10位包含大小写字母和数字");
return null;
}
// 调用修改密码的后端逻辑
if(!ChangePassword.changePassword(currentUsername, confirmPwd)){
showAlert("错误", "密码修改失败");
return null;
}
else{
showAlert("成功", "密码修改成功!");

@ -16,6 +16,15 @@ public class RegisterView {
private Scene scene;
private final SceneManager sceneManager;
// 将UI组件声明为类的成员变量
private TextField usernameField;
private TextField emailField;
private TextField codeField;
private PasswordField passwordField;
private PasswordField confirmPasswordField;
private Label statusLabel;
private Button sendCodeButton;
public RegisterView(SceneManager sceneManager) {
this.sceneManager = sceneManager;
createScene();
@ -30,31 +39,31 @@ public class RegisterView {
titleLabel.setFont(Font.font(20));
// 添加用户名输入框
TextField usernameField = new TextField();
usernameField = new TextField();
usernameField.setPromptText("请输入用户名(3-20位字母、数字、下划线)");
usernameField.setMaxWidth(300);
usernameField.setPrefHeight(35);
TextField emailField = new TextField();
emailField = new TextField();
emailField.setPromptText("请输入邮箱");
emailField.setMaxWidth(300);
emailField.setPrefHeight(35);
Button sendCodeButton = new Button("发送验证码");
sendCodeButton = new Button("发送验证码");
sendCodeButton.setStyle("-fx-background-color: #FF9800; -fx-text-fill: white;");
sendCodeButton.setPrefSize(120, 35);
TextField codeField = new TextField();
codeField = new TextField();
codeField.setPromptText("请输入验证码");
codeField.setMaxWidth(300);
codeField.setPrefHeight(35);
PasswordField passwordField = new PasswordField();
passwordField = new PasswordField();
passwordField.setPromptText("请输入密码(6-10位含大小写字母和数字)");
passwordField.setMaxWidth(300);
passwordField.setPrefHeight(35);
PasswordField confirmPasswordField = new PasswordField();
confirmPasswordField = new PasswordField();
confirmPasswordField.setPromptText("请再次输入密码");
confirmPasswordField.setMaxWidth(300);
confirmPasswordField.setPrefHeight(35);
@ -67,7 +76,7 @@ public class RegisterView {
backButton.setStyle("-fx-background-color: #757575; -fx-text-fill: white;");
backButton.setPrefSize(300, 35);
Label statusLabel = new Label();
statusLabel = new Label();
sendCodeButton.setOnAction(e -> {
String username = usernameField.getText().trim();
@ -159,7 +168,8 @@ public class RegisterView {
if (Register.register(username, email, password)) {
showSuccess(statusLabel, "注册成功!用户名: " + username);
sceneManager.showLoginView();
sceneManager.setCurrentUserName(username);
sceneManager.showMainMenuView();
} else {
showError(statusLabel, "注册失败,请检查信息!");
}
@ -185,6 +195,22 @@ public class RegisterView {
scene = new Scene(root, 400, 550); // 增加高度以适应新字段
}
/**
*
*/
public void clearFields() {
usernameField.clear();
emailField.clear();
codeField.clear();
passwordField.clear();
confirmPasswordField.clear();
statusLabel.setText("");
// 重置发送验证码按钮状态
sendCodeButton.setText("发送验证码");
sendCodeButton.setDisable(false);
}
private void startCountdown(Button button) {
new Thread(() -> {
try {
@ -218,12 +244,13 @@ public class RegisterView {
public Scene getScene() {
return scene;
}
public static boolean isValidUsername(String username) {
if (username == null || username.trim().isEmpty()) {
return false;
}
// 用户名规则:只包含英文字母和数字
String usernameRegex = "^[a-zA-Z0-9]{3,100}$";
// 用户名规则:只包含英文字母和数字,不限制长度
String usernameRegex = "^[a-zA-Z0-9]+$";
return Pattern.matches(usernameRegex, username.trim());
}
}
}

@ -1,2 +1,2 @@
wsf,3310207578@qq.com,Wsf1234
ybw,1798231811@qq.com,Ybw1234
wsf,3310207578@qq.com,Wsf1234

Loading…
Cancel
Save