User can login now (story 3)

main
Fan-Wu Yang 9 years ago
parent b00a50d2b8
commit 7b96c122eb

@ -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);
}
}

@ -52,6 +52,10 @@ public class User {
}
public boolean checkPassword(String p){
return p.equals(password);
}
public void serialise(){
try {
BufferedImage bi = SwingFXUtils.fromFXImage(photo, null);

@ -23,8 +23,7 @@
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="120.0" minHeight="10.0" prefHeight="120.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
@ -47,6 +46,7 @@
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Username:" />
@ -55,9 +55,10 @@
<PasswordField fx:id="password" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button mnemonicParsing="false" onAction="#login" text="Login" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
<Button mnemonicParsing="false" onAction="#register" text="Register" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
<Label text="Login As:" GridPane.rowIndex="2" />
<ComboBox fx:id="accountType" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
<Label text="Note for now as long as the username is the same as the password the application will work." GridPane.columnSpan="2147483647" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
</children>
</GridPane>
</children>

Binary file not shown.

@ -23,8 +23,7 @@
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="80.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="120.0" minHeight="10.0" prefHeight="120.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
@ -47,6 +46,7 @@
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Username:" />
@ -55,9 +55,10 @@
<PasswordField fx:id="password" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button mnemonicParsing="false" onAction="#login" text="Login" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
<Button mnemonicParsing="false" onAction="#register" text="Register" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
<Label text="Login As:" GridPane.rowIndex="2" />
<ComboBox fx:id="accountType" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
<Label text="Note for now as long as the username is the same as the password the application will work." GridPane.columnSpan="2147483647" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
</children>
</GridPane>
</children>

Loading…
Cancel
Save