删除登录时的邮箱验证

pull/5/head
梁晨旭 2 months ago
parent 97122ce22b
commit 580270ef9f

@ -24,7 +24,7 @@ public class ExamController {
@FXML private Button verifyRegisterCodeButton; @FXML private Button verifyRegisterCodeButton;
@FXML private Label registerStatusLabel; @FXML private Label registerStatusLabel;
private final Map<String, RegisterInfo> pendingRegistratrations = new HashMap<>();
// 登录界面控件 // 登录界面控件
@FXML private TextField usernameField; @FXML private TextField usernameField;
@FXML private PasswordField passwordField; @FXML private PasswordField passwordField;
@ -35,6 +35,8 @@ public class ExamController {
@FXML private Button verifyCodeButton; @FXML private Button verifyCodeButton;
@FXML private Label emailStatusLabel; @FXML private Label emailStatusLabel;
@FXML private Label loginStatusLabel; @FXML private Label loginStatusLabel;
@FXML private Button registerButton;
// 考试设置界面控件 // 考试设置界面控件
@FXML private VBox examSetupPanel; @FXML private VBox examSetupPanel;
@ -86,9 +88,7 @@ public class ExamController {
setupLevelComboBox(); setupLevelComboBox();
examSetupPanel.setVisible(false); examSetupPanel.setVisible(false);
questionCountField.setText("10"); questionCountField.setText("10");
if (emailStatusLabel != null) {
emailStatusLabel.setText("");
}
if (registerPanel != null) { if (registerPanel != null) {
registerPanel.setVisible(false); 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 @FXML
private void handleVerifyRegisterCode() { private void handleVerifyRegisterCode() {
@ -167,12 +138,20 @@ private void handleVerifyRegisterCode() {
boolean isValid = emailCodeService.verifyCode(email, code); boolean isValid = emailCodeService.verifyCode(email, code);
if (isValid) { 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) { if (setPasswordPanel != null) {
setPasswordPanel.setVisible(true); setPasswordPanel.setVisible(true);
}
} else {
registerStatusLabel.setText("注册信息丢失,请重新注册");
registerStatusLabel.setStyle("-fx-text-fill: red;");
} }
} else { } else {
registerStatusLabel.setText("验证码错误或已过期"); registerStatusLabel.setText("验证码错误或已过期");
@ -181,6 +160,7 @@ private void handleVerifyRegisterCode() {
} }
@FXML @FXML
private void showRegisterPanel() { private void showRegisterPanel() {
if (registerPanel != null) { if (registerPanel != null) {
@ -315,7 +295,7 @@ private void handleRegisterUser() {
// 发送注册验证码 // 发送注册验证码
emailCodeService.sendCode(email); emailCodeService.sendCode(email);
// 生成临时注册信息(密码将在后续设置) // 生成验证码并创建注册信息(密码将在后续设置)
String tempPassword = ""; // 临时空密码 String tempPassword = ""; // 临时空密码
RegisterInfo registerInfo = new RegisterInfo(username, tempPassword, email, ""); RegisterInfo registerInfo = new RegisterInfo(username, tempPassword, email, "");
pendingRegistrations.put(email, registerInfo); pendingRegistrations.put(email, registerInfo);
@ -328,6 +308,7 @@ private void handleRegisterUser() {
} }
} }
/** /**
* *
*/ */
@ -483,11 +464,7 @@ private void handleRegisterUser() {
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;");
@ -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() { private void startExam() {

@ -54,25 +54,6 @@
</font> </font>
</Label> </Label>
<PasswordField fx:id="passwordField" promptText="请输入密码" prefWidth="180.0" style="-fx-background-color: white; -fx-background-radius: 8; -fx-border-color: #8A2BE2; -fx-border-radius: 8; -fx-border-width: 2; -fx-padding: 8;"/> <PasswordField fx:id="passwordField" promptText="请输入密码" prefWidth="180.0" style="-fx-background-color: white; -fx-background-radius: 8; -fx-border-color: #8A2BE2; -fx-border-radius: 8; -fx-border-width: 2; -fx-padding: 8;"/>
</HBox>
<HBox spacing="15.0" alignment="CENTER_LEFT">
<Label text="📧 邮箱:" minWidth="80.0" textFill="#6A0DAD">
<font>
<Font name="System Bold" size="14.0"/>
</font>
</Label>
<TextField fx:id="emailField" promptText="请输入邮箱" prefWidth="180.0" style="-fx-background-color: white; -fx-background-radius: 8; -fx-border-color: #8A2BE2; -fx-border-radius: 8; -fx-border-width: 2; -fx-padding: 8;"/>
<Button fx:id="sendCodeButton" text="发送验证码" onAction="#handleSendEmailCode" style="-fx-background-color: linear-gradient(to right, #8A2BE2, #9932CC); -fx-text-fill: white; -fx-background-radius: 10; -fx-padding: 8 16; -fx-font-size: 12; -fx-font-weight: bold; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 5, 0, 0, 2);"/>
</HBox>
<HBox spacing="15.0" alignment="CENTER_LEFT">
<Label text="🔏 验证码:" minWidth="80.0" textFill="#6A0DAD">
<font>
<Font name="System Bold" size="14.0"/>
</font>
</Label>
<TextField fx:id="emailCodeField" promptText="请输入6位验证码" prefWidth="180.0" style="-fx-background-color: white; -fx-background-radius: 8; -fx-border-color: #8A2BE2; -fx-border-radius: 8; -fx-border-width: 2; -fx-padding: 8;"/>
<Button fx:id="verifyCodeButton" text="验证" onAction="#handleVerifyEmailCode" style="-fx-background-color: linear-gradient(to right, #8A2BE2, #9932CC); -fx-text-fill: white; -fx-background-radius: 10; -fx-padding: 8 16; -fx-font-size: 12; -fx-font-weight: bold; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 5, 0, 0, 2);"/>
<Label fx:id="emailStatusLabel" textFill="#8B0000" style="-fx-font-weight: bold;"/>
</HBox> </HBox>
<HBox spacing="15.0" alignment="CENTER_LEFT"> <HBox spacing="15.0" alignment="CENTER_LEFT">
<Button fx:id="loginButton" text="🚀 登录" onAction="#handleLogin" style="-fx-background-color: linear-gradient(to right, #8A2BE2, #9932CC); -fx-text-fill: white; -fx-background-radius: 10; -fx-padding: 10 20; -fx-font-size: 14; -fx-font-weight: bold; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 5, 0, 0, 2);"/> <Button fx:id="loginButton" text="🚀 登录" onAction="#handleLogin" style="-fx-background-color: linear-gradient(to right, #8A2BE2, #9932CC); -fx-text-fill: white; -fx-background-radius: 10; -fx-padding: 10 20; -fx-font-size: 14; -fx-font-weight: bold; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 5, 0, 0, 2);"/>

Loading…
Cancel
Save