Story 2 is complete

main
Fan-Wu Yang 9 years ago
parent 19600bf86f
commit b00a50d2b8

@ -51,7 +51,7 @@ public class RegisterController extends Controller {
return failure;
}
public String validateEmail(String email){
public static String validateEmail(String email){
String failure = "";
Pattern uclivePattern = Pattern.compile(".*@uclive.ac.nz", Pattern.CASE_INSENSITIVE);
Pattern canterburyPattern = Pattern.compile(".*@canterbury.ac.nz", Pattern.CASE_INSENSITIVE);
@ -61,7 +61,7 @@ public class RegisterController extends Controller {
return failure;
}
public String validatePassword(String p1, String p2){
public static String validatePassword(String p1, String p2){
String failure = "";
if (p1.length() < 6){
failure += "Your password must be at least 6 letters long.\n";
@ -72,7 +72,7 @@ public class RegisterController extends Controller {
return failure;
}
public String validateAddress(String address){
public static String validateAddress(String address){
String failure = "";
if (!DataValidator.addressValidator(address)){
failure += "Your address must be similar to 1 University Drive or 1/1 University Drive or 1A/2 University Drive or 1A/2A University Drive.\n";
@ -80,7 +80,7 @@ public class RegisterController extends Controller {
return failure;
}
public String validatePhone(String hp, String mp){
public static String validatePhone(String hp, String mp){
String failure = "";
if ((hp.equals("") || hp == null) && (mp.equals("")||mp == null)){
failure += "You must enter either a home phone number or a mobile phone number.\n";

@ -0,0 +1,128 @@
package controllers;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import model.Driver;
import model.SceneCode;
import model.Session;
import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;
/**
* Created by Gondr on 1/06/2017.
*/
public class RegisterDriverController extends Controller {
private Image photoStored;
private int studentNumber;
private String email;
private String password;
private String address;
private String homephone;
private String mobilephone;
private String accountType;
@FXML
private ComboBox<String> licenseType;
@FXML
private TextField number;
@FXML
private DatePicker issue;
@FXML
private DatePicker expiry;
public void setUserInformation(int studentNumber, String email, String password, String address, String homephone, String mobilephone, String accountType, Image photoStored){
this.studentNumber = studentNumber;
this.email = email;
this.password = password;
this.address = address;
this.homephone = homephone;
this.mobilephone = mobilephone;
this.accountType = accountType;
this.photoStored = photoStored;
}
public static String validateLicense(String ln){
String failure = "";
if (ln.length() < 6){
failure += "Your License must be at least 6 letters long.\n";
}
return failure;
}
public static String validateIssue(LocalDate d){
String failure = "";
if (d == null){
failure += "You must set a date of issue.\n";
}else {
if (LocalDate.now().isBefore(d)) {
failure += "You cannot have a issue date earlier than today.\n";
}
}
return failure;
}
public static String validateExpire(LocalDate e, LocalDate i){
String failure = "";
if (e == null){
failure += "You must set a date of expiry.\n";
} else {
if (i != null) {
if (e.isBefore(i)) {
failure += "You cannot have your expiry date before your date of issue.\n";
}
}
}
return failure;
}
public boolean validate(){
String failure = "";
failure += validateLicense(number.getText());
failure += validateIssue(issue.getValue());
failure += validateExpire(expiry.getValue(), issue.getValue());
if (failure.equals("")){
return true;
}else{
popUp(Alert.AlertType.WARNING, "Error!", "Your details are not valid for the following reasons.", failure);
return false;
}
}
public void createAccount(){
if (validate()){
Driver.LicenseType lc = Driver.LicenseType.getValueOf(licenseType.getValue());
Driver driver = new Driver(studentNumber, email, password, address,homephone, mobilephone, photoStored, lc, number.getText(), issue.getValue(), expiry.getValue());
if (Session.session.getDataManager().addDriver(driver)){
popUp(Alert.AlertType.CONFIRMATION, "Success!", "Your Account has been made.", "You can now log in and will be redirected the the title screen after.");
try {
changeScene(SceneCode.MAIN);
} catch (Exception e) {
e.printStackTrace();
}
}else {
popUp(Alert.AlertType.WARNING, "Error!", "There is already an passenger with this id.", "You will be redirected to the homescreen to log in.");
try {
changeScene(SceneCode.MAIN);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
ObservableList<String> licenseTypes = FXCollections.observableArrayList();
licenseTypes.addAll(Driver.LicenseType.RESTRICTED.name, Driver.LicenseType.FULL.name, Driver.LicenseType.FULL2YEARS.name);
licenseType.setItems(licenseTypes);
licenseType.getSelectionModel().select(0);
}
}

@ -59,6 +59,10 @@ public class UploadPhotoController extends Controller {
}
public void next(){
if (photoStored == null){
popUp(Alert.AlertType.WARNING, "Error!", "Missing Photo.", "You must have a photo with your account.");
return;
}
User.AccountType ac = User.AccountType.getValueOf(accountType);
if (ac == User.AccountType.PASSENGER){
User user = new User(studentNumber, email, password, address,homephone, mobilephone, photoStored);
@ -78,7 +82,13 @@ public class UploadPhotoController extends Controller {
}
}
}else{
//changeScene()
try {
RegisterDriverController c = (RegisterDriverController) changeScene(SceneCode.REGISTER_DRIVER);
c.setUserInformation(studentNumber, email, password, address,
homephone, mobilephone, accountType, photoStored);
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -120,7 +120,17 @@ public class DataManager {
return users;
}
public boolean addDriver(Driver driver){
if (!drivers.containsKey(String.valueOf(driver.studentNumber))) {
drivers.put(String.valueOf(driver.studentNumber), driver);
return true;
}
return false;
}
public Map<String, Driver> getDrivers() {
return drivers;
}
}

@ -3,6 +3,7 @@ package model;
import javafx.scene.image.Image;
import java.awt.image.BufferedImage;
import java.time.LocalDate;
/**
* Created by Gondr on 1/06/2017.
@ -11,8 +12,8 @@ public class Driver extends User{
protected LicenseType licenseType;
protected String licenseNumber;
protected String licenseDateIssued;
protected String licenseDateExpire;
protected LocalDate licenseDateIssued;
protected LocalDate licenseDateExpire;
public enum LicenseType{
RESTRICTED("Restricted"), FULL("Full"), FULL2YEARS("Full for 2 Years");
@ -21,10 +22,22 @@ public class Driver extends User{
LicenseType(String name){
this.name = name;
}
public static LicenseType getValueOf(String s){
switch (s){
case "Restricted":
return RESTRICTED;
case "Full":
return FULL;
case "Full for 2 Years":
return FULL2YEARS;
default:
return null;
}
}
}
public Driver(int studentNumber, String email, String password, String address, String homephone, String mobilephone,
Image photo, LicenseType licenseType, String licenseNumber, String licenseDateIssued, String licenseDateExpire){
Image photo, LicenseType licenseType, String licenseNumber, LocalDate licenseDateIssued, LocalDate licenseDateExpire){
super(studentNumber, email, password, address, homephone, mobilephone, photo);
this.accountType = AccountType.DRIVER;
this.licenseType = licenseType;

@ -16,7 +16,7 @@ public enum SceneCode {
//screens after login
HOME("home"),ADD_RIDE("addride"),MY_RIDES("myrides"), ADD_STOPS("addstops"), MY_STOPS("mystops"), ADD_ROUTE("addroute"),
MY_ROUTES("myroutes"), ADD_TRIP("addtrip"), MY_TRIPS("mytrips"), SHARED_RIDES("sharedtrips"), SEARCH_STOPS("searchstops"),
REGISTER("register", false), ADD_PHOTO("addphoto", false);
REGISTER("register", false), ADD_PHOTO("addphoto", false), REGISTER_DRIVER("registerdriver", false);
private String path;
private boolean loadMenu;

@ -192,7 +192,7 @@ public class DataManagerSerialiser extends Serialiser {
HashMap<String, Driver> drivers = gson.fromJson(reader7, new TypeToken<HashMap<String, Driver>>(){}.getType());
reader7.close();
for (String driverkey: drivers.keySet()){
users.get(driverkey).deserialise();
drivers.get(driverkey).deserialise();
}
return new DataManager(rides, stops, routes, trips, sharedTrips, users, drivers);

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.RegisterDriverController">
<children>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="0.0" prefWidth="75.0" />
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="0.0" prefWidth="75.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="60.0" minHeight="10.0" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="300.0" minHeight="10.0" prefHeight="300.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Register for UC Ride Sharing System" GridPane.columnSpan="3" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="22.0" />
</font>
</Label>
<GridPane GridPane.columnIndex="1" GridPane.rowIndex="2">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="120.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" />
</columnConstraints>
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="License Type:" />
<ComboBox fx:id="licenseType" prefWidth="150.0" GridPane.columnIndex="1" />
<Label text="License Number:" GridPane.rowIndex="1" />
<TextField fx:id="number" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Issue Date:" GridPane.rowIndex="2" />
<Label text="Expiry Date:" GridPane.rowIndex="3" />
<Button mnemonicParsing="false" onAction="#createAccount" text="Finish" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="4" />
<DatePicker fx:id="issue" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<DatePicker fx:id="expiry" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
</GridPane>
</children>
</AnchorPane>

Binary file not shown.

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.RegisterDriverController">
<children>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="0.0" prefWidth="75.0" />
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="0.0" prefWidth="75.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="60.0" minHeight="10.0" prefHeight="60.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="300.0" minHeight="10.0" prefHeight="300.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Register for UC Ride Sharing System" GridPane.columnSpan="3" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="22.0" />
</font>
</Label>
<GridPane GridPane.columnIndex="1" GridPane.rowIndex="2">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="120.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" />
</columnConstraints>
<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 minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="License Type:" />
<ComboBox fx:id="licenseType" prefWidth="150.0" GridPane.columnIndex="1" />
<Label text="License Number:" GridPane.rowIndex="1" />
<TextField fx:id="number" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Issue Date:" GridPane.rowIndex="2" />
<Label text="Expiry Date:" GridPane.rowIndex="3" />
<Button mnemonicParsing="false" onAction="#createAccount" text="Finish" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="4" />
<DatePicker fx:id="issue" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<DatePicker fx:id="expiry" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
</GridPane>
</children>
</AnchorPane>

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save