|
|
|
@ -20,6 +20,11 @@ public class ExamController {
|
|
|
|
@FXML private TextField usernameField;
|
|
|
|
@FXML private TextField usernameField;
|
|
|
|
@FXML private PasswordField passwordField;
|
|
|
|
@FXML private PasswordField passwordField;
|
|
|
|
@FXML private Button loginButton;
|
|
|
|
@FXML private Button loginButton;
|
|
|
|
|
|
|
|
@FXML private TextField emailField;
|
|
|
|
|
|
|
|
@FXML private TextField emailCodeField;
|
|
|
|
|
|
|
|
@FXML private Button sendCodeButton;
|
|
|
|
|
|
|
|
@FXML private Button verifyCodeButton;
|
|
|
|
|
|
|
|
@FXML private Label emailStatusLabel;
|
|
|
|
@FXML private Label loginStatusLabel;
|
|
|
|
@FXML private Label loginStatusLabel;
|
|
|
|
|
|
|
|
|
|
|
|
// 考试设置界面控件
|
|
|
|
// 考试设置界面控件
|
|
|
|
@ -39,6 +44,8 @@ public class ExamController {
|
|
|
|
private Map<Integer, String> userAnswers = new HashMap<>();
|
|
|
|
private Map<Integer, String> userAnswers = new HashMap<>();
|
|
|
|
private ChoiceQuestionGenerator questionGenerator;
|
|
|
|
private ChoiceQuestionGenerator questionGenerator;
|
|
|
|
private final Map<String, Account> userMap = new HashMap<>();
|
|
|
|
private final Map<String, Account> userMap = new HashMap<>();
|
|
|
|
|
|
|
|
private final EmailCodeService emailCodeService = new EmailCodeService();
|
|
|
|
|
|
|
|
private boolean emailVerified = false;
|
|
|
|
|
|
|
|
|
|
|
|
// 常量定义
|
|
|
|
// 常量定义
|
|
|
|
private static final int MIN_QUESTIONS = 5;
|
|
|
|
private static final int MIN_QUESTIONS = 5;
|
|
|
|
@ -50,6 +57,9 @@ public class ExamController {
|
|
|
|
setupLevelComboBox();
|
|
|
|
setupLevelComboBox();
|
|
|
|
examSetupPanel.setVisible(false);
|
|
|
|
examSetupPanel.setVisible(false);
|
|
|
|
questionCountField.setText("10");
|
|
|
|
questionCountField.setText("10");
|
|
|
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
|
|
|
emailStatusLabel.setText("");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initAccounts() {
|
|
|
|
private void initAccounts() {
|
|
|
|
@ -93,6 +103,11 @@ public class ExamController {
|
|
|
|
examSetupPanel.setVisible(true);
|
|
|
|
examSetupPanel.setVisible(true);
|
|
|
|
loginStatusLabel.setText("登录成功!");
|
|
|
|
loginStatusLabel.setText("登录成功!");
|
|
|
|
loginStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
loginStatusLabel.setStyle("-fx-text-fill: green;");
|
|
|
|
|
|
|
|
emailVerified = false;
|
|
|
|
|
|
|
|
if (emailStatusLabel != null) {
|
|
|
|
|
|
|
|
emailStatusLabel.setText("请进行邮箱验证后再开始考试");
|
|
|
|
|
|
|
|
emailStatusLabel.setStyle("-fx-text-fill: #8B0000;");
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
loginStatusLabel.setText("用户名或密码错误");
|
|
|
|
loginStatusLabel.setText("用户名或密码错误");
|
|
|
|
loginStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
loginStatusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
@ -110,6 +125,10 @@ public class ExamController {
|
|
|
|
passwordField.clear();
|
|
|
|
passwordField.clear();
|
|
|
|
loginStatusLabel.setText("");
|
|
|
|
loginStatusLabel.setText("");
|
|
|
|
statusLabel.setText("");
|
|
|
|
statusLabel.setText("");
|
|
|
|
|
|
|
|
emailVerified = false;
|
|
|
|
|
|
|
|
if (emailField != null) emailField.clear();
|
|
|
|
|
|
|
|
if (emailCodeField != null) emailCodeField.clear();
|
|
|
|
|
|
|
|
if (emailStatusLabel != null) emailStatusLabel.setText("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
@ -132,6 +151,12 @@ public class ExamController {
|
|
|
|
String selectedLevel = levelComboBox.getValue();
|
|
|
|
String selectedLevel = levelComboBox.getValue();
|
|
|
|
ChoiceQuestionGenerator.Level level = ChoiceQuestionGenerator.Level.valueOf(selectedLevel);
|
|
|
|
ChoiceQuestionGenerator.Level level = ChoiceQuestionGenerator.Level.valueOf(selectedLevel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!emailVerified) {
|
|
|
|
|
|
|
|
statusLabel.setText("请先完成邮箱验证码验证");
|
|
|
|
|
|
|
|
statusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 生成考试题目
|
|
|
|
// 生成考试题目
|
|
|
|
questionGenerator = new ChoiceQuestionGenerator();
|
|
|
|
questionGenerator = new ChoiceQuestionGenerator();
|
|
|
|
examQuestions = questionGenerator.generateQuestions(level, count);
|
|
|
|
examQuestions = questionGenerator.generateQuestions(level, count);
|
|
|
|
@ -150,6 +175,57 @@ public class ExamController {
|
|
|
|
statusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
statusLabel.setStyle("-fx-text-fill: red;");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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;");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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() {
|
|
|
|
private void startExam() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|