@ -1,12 +1,13 @@
package controllers ;
import javafx.collections.FXCollections ;
import javafx.collections.ObservableList ;
import javafx.fxml.FXML ;
import javafx.fxml.Initializable ;
import javafx.scene.control.Alert ;
import javafx.scene.control.Control ;
import javafx.scene.control.PasswordField ;
import javafx.scene.control.TextField ;
import javafx.scene.control.* ;
import model.SceneCode ;
import model.Session ;
import model.User ;
import java.net.URL ;
import java.util.ResourceBundle ;
@ -20,13 +21,18 @@ public class MainController extends Controller{
TextField username ;
@FXML
PasswordField password ;
@FXML
private ComboBox < String > accountType ;
public void register ( ) throws Exception {
changeScene ( SceneCode . REGISTER ) ;
}
public boolean validateLogin ( String user , String pass ) {
if ( user . equals ( pass ) ) {
if ( Session . session . getDataManager ( ) . getUsers ( ) . get ( user ) . checkPassword ( pass ) & & User . AccountType . getValueOf ( accountType . getValue ( ) ) = = User . AccountType . PASSENGER ) {
return true ;
}
if ( Session . session . getDataManager ( ) . getDrivers ( ) . get ( user ) . checkPassword ( pass ) & & User . AccountType . getValueOf ( accountType . getValue ( ) ) = = User . AccountType . DRIVER ) {
return true ;
}
return false ;
@ -44,6 +50,9 @@ public class MainController extends Controller{
@Override
public void initialize ( URL location , ResourceBundle resources ) {
ObservableList < String > accountTypes = FXCollections . observableArrayList ( ) ;
accountTypes . addAll ( User . AccountType . DRIVER . name , User . AccountType . PASSENGER . name ) ;
accountType . setItems ( accountTypes ) ;
accountType . getSelectionModel ( ) . select ( 0 ) ;
}
}