You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
// RegisterViewController.java
|
|
package com.student.mathquiz.view;
|
|
|
|
import com.student.mathquiz.MainApp;
|
|
import javafx.application.Platform;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.TextField;
|
|
|
|
public class RegisterViewController {
|
|
public TextField codeField;
|
|
public TextField emailField;
|
|
@FXML private Label statusLabel;
|
|
|
|
private MainApp mainApp;
|
|
|
|
public void setMainApp(MainApp mainApp) {
|
|
this.mainApp = mainApp;
|
|
}
|
|
|
|
@FXML
|
|
private void handleSendCode() {
|
|
// TODO: 在这里调用后端 userService.sendVerificationCode(...)
|
|
String email = emailField.getText();
|
|
|
|
// TODO: 在这里先加一个邮箱格式校验
|
|
|
|
String code = EmailService.generateVerificationCode();
|
|
|
|
// ★★★ 在后台线程中发送邮件,防止界面卡死! ★★★
|
|
new Thread(() -> {
|
|
boolean success = EmailService.sendVerificationEmail(email, code);
|
|
|
|
// 在 JavaFX 主线程中更新界面
|
|
Platform.runLater(() -> {
|
|
if (success) {
|
|
statusLabel.setText("验证码已发送至您的邮箱,请查收!");
|
|
// TODO: 把 code 和 email 存起来,用于稍后的验证
|
|
} else {
|
|
statusLabel.setText("验证码发送失败,请检查邮箱地址或网络!");
|
|
}
|
|
});
|
|
}).start();
|
|
|
|
}
|
|
|
|
@FXML
|
|
private void handleRegister() {
|
|
// TODO: 在这里进行输入校验,并调用后端 userService.register(...)
|
|
statusLabel.setText("注册成功(伪)!请登录。");
|
|
mainApp.showLoginView();
|
|
}
|
|
|
|
@FXML
|
|
private void handleGoToLogin() {
|
|
mainApp.showLoginView();
|
|
}
|
|
}
|
|
// 在 RegisterViewController.java 里
|