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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package com.student.mathquiz.view ;
import com.student.mathquiz.MainApp ;
import com.student.mathquiz.service.IUserService ;
import javafx.fxml.FXML ;
import javafx.scene.control.Label ;
import javafx.scene.control.PasswordField ;
import javafx.scene.control.TextField ;
public class LoginViewController {
@FXML private TextField emailField ;
@FXML private PasswordField passwordField ;
@FXML private Label statusLabel ;
private MainApp mainApp ;
private IUserService userService ;
public void setMainApp ( MainApp mainApp ) {
this . mainApp = mainApp ;
this . userService = mainApp . getUserService ( ) ;
}
// 在 LoginViewController.java 中
@FXML
private void handleLogin ( ) {
String identifier = emailField . getText ( ) ; // 我们把变量名改得更准确
String password = passwordField . getText ( ) ;
// ★★★ 调用新的 login 方法,它会返回一个 User 对象 ★★★
com . student . mathquiz . model . User loggedInUser = userService . login ( identifier , password ) ;
if ( loggedInUser ! = null ) { // 如果返回的不是 null, 说明登录成功
// ★★★ 把完整的 User 对象传给 MainApp ★★★
mainApp . handleLoginSuccess ( loggedInUser ) ;
} else {
statusLabel . setText ( "用户名/邮箱或密码错误!" ) ;
}
}
@FXML
private void handleGoToRegister ( ) {
mainApp . showRegisterView ( ) ;
}
}