|
|
|
|
@ -24,7 +24,7 @@ public class ExamController {
|
|
|
|
|
@FXML private Button verifyRegisterCodeButton;
|
|
|
|
|
@FXML private Label registerStatusLabel;
|
|
|
|
|
|
|
|
|
|
private final Map<String, RegisterInfo> pendingRegistratrations = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 登录界面控件
|
|
|
|
|
@FXML private TextField usernameField;
|
|
|
|
|
@FXML private PasswordField passwordField;
|
|
|
|
|
@ -35,6 +35,8 @@ public class ExamController {
|
|
|
|
|
@FXML private Button verifyCodeButton;
|
|
|
|
|
@FXML private Label emailStatusLabel;
|
|
|
|
|
@FXML private Label loginStatusLabel;
|
|
|
|
|
@FXML private Button registerButton;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 考试设置界面控件
|
|
|
|
|
@FXML private VBox examSetupPanel;
|
|
|
|
|
@ -86,9 +88,7 @@ public class ExamController {
|
|
|
|
|
setupLevelComboBox();
|
|
|
|
|
examSetupPanel.setVisible(false);
|
|
|
|
|
questionCountField.setText("10");
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (registerPanel != null) {
|
|
|
|
|
registerPanel.setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
@ -122,35 +122,6 @@ public class ExamController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加注册相关方法
|
|
|
|
|
@FXML
|
|
|
|
|
private void handleRegister() {
|
|
|
|
|
|
|
|
|
|
String username = registerUsernameField.getText().trim();
|
|
|
|
|
String email = registerEmailField.getText().trim();
|
|
|
|
|
|
|
|
|
|
if (username.isEmpty() || email.isEmpty()) {
|
|
|
|
|
registerStatusLabel.setText("请填写用户名和邮箱");
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userMap.containsKey(username)) {
|
|
|
|
|
registerStatusLabel.setText("用户名已存在");
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 发送注册验证码
|
|
|
|
|
emailCodeService.sendCode(email);
|
|
|
|
|
registerStatusLabel.setText("验证码已发送到邮箱,请查收");
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
registerStatusLabel.setText("发送验证码失败:" + e.getMessage());
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
private void handleVerifyRegisterCode() {
|
|
|
|
|
@ -167,12 +138,20 @@ private void handleVerifyRegisterCode() {
|
|
|
|
|
boolean isValid = emailCodeService.verifyCode(email, code);
|
|
|
|
|
|
|
|
|
|
if (isValid) {
|
|
|
|
|
registerStatusLabel.setText("验证码验证成功,请设置密码");
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
// 检查是否有待处理的注册信息
|
|
|
|
|
RegisterInfo registerInfo = pendingRegistrations.get(email);
|
|
|
|
|
if (registerInfo != null) {
|
|
|
|
|
registerInfo.codeVerified = true;
|
|
|
|
|
registerStatusLabel.setText("验证码验证成功,请设置密码");
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
|
|
|
|
|
// 显示设置密码面板
|
|
|
|
|
if (setPasswordPanel != null) {
|
|
|
|
|
setPasswordPanel.setVisible(true);
|
|
|
|
|
// 显示设置密码面板
|
|
|
|
|
if (setPasswordPanel != null) {
|
|
|
|
|
setPasswordPanel.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
registerStatusLabel.setText("注册信息丢失,请重新注册");
|
|
|
|
|
registerStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
registerStatusLabel.setText("验证码错误或已过期");
|
|
|
|
|
@ -181,6 +160,7 @@ private void handleVerifyRegisterCode() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
private void showRegisterPanel() {
|
|
|
|
|
if (registerPanel != null) {
|
|
|
|
|
@ -315,7 +295,7 @@ private void handleRegisterUser() {
|
|
|
|
|
// 发送注册验证码
|
|
|
|
|
emailCodeService.sendCode(email);
|
|
|
|
|
|
|
|
|
|
// 生成临时注册信息(密码将在后续设置)
|
|
|
|
|
// 生成验证码并创建注册信息(密码将在后续设置)
|
|
|
|
|
String tempPassword = ""; // 临时空密码
|
|
|
|
|
RegisterInfo registerInfo = new RegisterInfo(username, tempPassword, email, "");
|
|
|
|
|
pendingRegistrations.put(email, registerInfo);
|
|
|
|
|
@ -328,6 +308,7 @@ private void handleRegisterUser() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示修改密码面板
|
|
|
|
|
*/
|
|
|
|
|
@ -483,11 +464,7 @@ private void handleRegisterUser() {
|
|
|
|
|
examSetupPanel.setVisible(true);
|
|
|
|
|
loginStatusLabel.setText("登录成功!");
|
|
|
|
|
loginStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
emailVerified = false;
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("请进行邮箱验证后再开始考试");
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: #8B0000;");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
loginStatusLabel.setText("用户名或密码错误");
|
|
|
|
|
loginStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
@ -552,57 +529,8 @@ private void handleRegisterUser() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
private void handleSendEmailCode() {
|
|
|
|
|
String email = emailField != null ? emailField.getText().trim() : "";
|
|
|
|
|
if (email.isEmpty()) {
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("请输入邮箱");
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
emailCodeService.sendCode(email);
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("验证码已发送,请在5分钟内查收(控制台可见)");
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("发送失败:" + ex.getMessage());
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修正 handleVerifyEmailCode 方法,应该用于登录前的邮箱验证而不是注册
|
|
|
|
|
@FXML
|
|
|
|
|
private void handleVerifyEmailCode() {
|
|
|
|
|
String email = emailField != null ? emailField.getText().trim() : "";
|
|
|
|
|
String code = emailCodeField != null ? emailCodeField.getText().trim() : "";
|
|
|
|
|
if (email.isEmpty() || code.isEmpty()) {
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("请输入邮箱和验证码");
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
boolean ok = emailCodeService.verifyCode(email, code);
|
|
|
|
|
if (ok) {
|
|
|
|
|
emailVerified = true;
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("邮箱验证成功,可开始考试");
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
emailVerified = false;
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
emailStatusLabel.setText("验证码错误或已过期");
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void startExam() {
|
|
|
|
|
|