Compare commits
2 Commits
9750a48d68
...
b9ccf98bf6
Author | SHA1 | Date | |
---|---|---|---|
b9ccf98bf6 | |||
159f04271c |
@ -3,7 +3,9 @@ package com.example.vpr_javafx;
|
|||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -285,7 +287,10 @@ public class Data {
|
|||||||
/**
|
/**
|
||||||
* The method validates the user input
|
* The method validates the user input
|
||||||
*
|
*
|
||||||
* @return boolean inputValid
|
* @param tfPhone Phone number the user typed in
|
||||||
|
* @param pfPassword Password the user typed in
|
||||||
|
* @param controller Controller
|
||||||
|
* @return phoneNumberValid && passwordValid
|
||||||
* @author Kevin Maier, Kevin Pfannenstiel
|
* @author Kevin Maier, Kevin Pfannenstiel
|
||||||
*/
|
*/
|
||||||
public boolean validateData(TextField tfPhone, PasswordField pfPassword, HelloController controller)
|
public boolean validateData(TextField tfPhone, PasswordField pfPassword, HelloController controller)
|
||||||
@ -295,6 +300,8 @@ public class Data {
|
|||||||
boolean phoneNumberValid = false;
|
boolean phoneNumberValid = false;
|
||||||
boolean passwordValid = false;
|
boolean passwordValid = false;
|
||||||
|
|
||||||
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
|
|
||||||
HashMap<String, String> users = readLoginData();
|
HashMap<String, String> users = readLoginData();
|
||||||
|
|
||||||
String phoneNumber = tfPhone.getText();
|
String phoneNumber = tfPhone.getText();
|
||||||
@ -305,10 +312,8 @@ public class Data {
|
|||||||
|
|
||||||
if (password.isEmpty() || phoneNumber.isEmpty())
|
if (password.isEmpty() || phoneNumber.isEmpty())
|
||||||
{
|
{
|
||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
alert.setContentText("Login fehlgeschlagen. Anmeldedaten unvollständig.");
|
||||||
alert.setContentText("Login fehlgeschlagen. Es wurde nichts eingegeben.");
|
|
||||||
alert.show();
|
alert.show();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
|
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
|
||||||
@ -319,22 +324,18 @@ public class Data {
|
|||||||
|
|
||||||
if (!users.containsKey(phoneNumber) || !phoneNumberMatchFound || phoneNumber.length() >= 15)
|
if (!users.containsKey(phoneNumber) || !phoneNumberMatchFound || phoneNumber.length() >= 15)
|
||||||
{
|
{
|
||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
|
||||||
alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch.");
|
alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch.");
|
||||||
alert.show();
|
alert.show();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
phoneNumberValid = true;
|
phoneNumberValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!users.get(phoneNumber).equals(password) || !passwordMatchFound || password.length() <8)
|
if (!users.get(phoneNumber).equals(password) || !passwordMatchFound)
|
||||||
{
|
{
|
||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
|
||||||
alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch.");
|
alert.setContentText("Login fehlgeschlagen. Die eingegebenen Daten sind falsch.");
|
||||||
alert.show();
|
alert.show();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -345,6 +346,78 @@ public class Data {
|
|||||||
return phoneNumberValid && passwordValid;
|
return phoneNumberValid && passwordValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param tfPhone
|
||||||
|
* @param pfPassword
|
||||||
|
* @param controller
|
||||||
|
* @author Kevin Maier
|
||||||
|
*/
|
||||||
|
public boolean validateRegistration(TextField tfName, TextField tfPhone, PasswordField pfPassword, TextField tfStreet, TextField tfHouseNumber, TextField tfPostalCode, TextField tfCity, TextField tfChild, HelloController controller)
|
||||||
|
{
|
||||||
|
boolean phoneNumberMatchFound;
|
||||||
|
boolean passwordMatchFound;
|
||||||
|
boolean postalCodeFound;
|
||||||
|
boolean phoneNumberValid = false;
|
||||||
|
boolean passwordValid = false;
|
||||||
|
boolean postalCodeValid = false;
|
||||||
|
|
||||||
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
|
|
||||||
|
HashMap<String, String> users = readLoginData();
|
||||||
|
|
||||||
|
String phoneNumber = tfPhone.getText();
|
||||||
|
String password = pfPassword.getText();
|
||||||
|
String postalCode = tfPostalCode.getText();
|
||||||
|
|
||||||
|
Pattern phoneNumberPattern = Pattern.compile("[0-9]*");
|
||||||
|
Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$");
|
||||||
|
Pattern postalCodePattern = Pattern.compile("[0-9]{5}");
|
||||||
|
|
||||||
|
if (tfName.getText().isEmpty() || tfPhone.getText().isEmpty() || pfPassword.getText().isEmpty() || tfStreet.getText().isEmpty() || tfHouseNumber.getText().isEmpty() || tfPostalCode.getText().isEmpty() || tfCity.getText().isEmpty() || tfChild.getText().isEmpty())
|
||||||
|
{
|
||||||
|
alert.setContentText("Registrierung fehlgeschlagen. Registrierungsdaten unvollständig.");
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
|
||||||
|
Matcher passwordMatcher = passwordPattern.matcher(password);
|
||||||
|
Matcher postalCodeMatcher = postalCodePattern.matcher(postalCode);
|
||||||
|
|
||||||
|
phoneNumberMatchFound = phoneNumberMatcher.find();
|
||||||
|
passwordMatchFound = passwordMatcher.find();
|
||||||
|
postalCodeFound = postalCodeMatcher.find();
|
||||||
|
|
||||||
|
if (users.containsKey(phoneNumber) || !phoneNumberMatchFound || phoneNumber.length() >= 15)
|
||||||
|
{
|
||||||
|
alert.setContentText("Registrierung fehlgeschlagen. Die eingegebenen Telefonnummer ist bereits vergeben oder ist nicht korrekt.");
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
phoneNumberValid = true;
|
||||||
|
}
|
||||||
|
if (!passwordMatchFound)
|
||||||
|
{
|
||||||
|
alert.setContentText("Registrierung fehlgeschlagen. Das Passwort muss mindestens 8 Zeichen lang sein und mindestens 1 Ziffer und 1 Zeichen beinhalten.");
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
passwordValid = true;
|
||||||
|
}
|
||||||
|
if (!postalCodeFound)
|
||||||
|
{
|
||||||
|
alert.setContentText("Registrierung fehlgeschlagen. Die Postleitzahl ist nicht richtig.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
postalCodeValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return phoneNumberValid && passwordValid && postalCodeValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method changes the orders.txt file by removing canceled orders
|
* The method changes the orders.txt file by removing canceled orders
|
||||||
|
@ -304,7 +304,7 @@ public class HelloController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OnRegistrationButton() lässt einen neuen Nutzer anlegen
|
* OnRegistrationButton() creates a new user
|
||||||
* @param event
|
* @param event
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @author Kevin Maier
|
* @author Kevin Maier
|
||||||
@ -313,17 +313,18 @@ public class HelloController {
|
|||||||
protected void OnRegistrationButton(ActionEvent event) throws IOException
|
protected void OnRegistrationButton(ActionEvent event) throws IOException
|
||||||
{
|
{
|
||||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
Data validData = new Data("user.txt");
|
Data validRegistration = new Data("user.txt");
|
||||||
|
|
||||||
if (tfName.getText().isEmpty() || tfPhone.getText().isEmpty() || tfChild.getText().isEmpty())
|
if (validRegistration.validateRegistration(tfName, tfPhone, pfPassword, tfStreet, tfHouseNumber, tfPostalCode, tfCity, tfChild, this))
|
||||||
{
|
{
|
||||||
alert.setContentText("Registrierungsdaten unvollständig");
|
try (FileWriter writer = new FileWriter("user.txt", true)){
|
||||||
}
|
writer.write(tfName.getText() + ";" + tfStreet.getText() + " " + tfHouseNumber.getText() + "," + tfPostalCode.getText() + " " + tfCity.getText() + ";" + tfPhone.getText() + ";" + tfChild.getText() + ";" + pfPassword.getText() + System.lineSeparator());
|
||||||
else if (validData.validateData(tfPhone, pfPassword, this))
|
|
||||||
{
|
Parent root = FXMLLoader.load(getClass().getResource("MenuOverview-view.fxml"));
|
||||||
try (FileWriter writer = new FileWriter("user.txt")){
|
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
|
||||||
writer.write(tfName.getText() + ";" + tfStreet.getText() + " " + tfHouseNumber.getText() + "," + tfPostalCode + " " + tfCity.getText() + ";" + tfPhone.getText() + ";" + tfChild.getText() + ";" + pfPassword.getText());
|
Scene scene = new Scene(root);
|
||||||
writer.flush();
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,14 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.vpr_javafx.HelloController">
|
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.vpr_javafx.HelloController">
|
||||||
<children>
|
<children>
|
||||||
<GridPane layoutX="100.0" layoutY="75.0" prefHeight="250.0" prefWidth="400.0">
|
<GridPane layoutX="50.0" layoutY="62.0" prefHeight="275.0" prefWidth="500.0">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="153.0" minWidth="10.0" prefWidth="89.8" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="153.0" minWidth="10.0" prefWidth="85.0" />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="261.0" minWidth="10.0" prefWidth="226.2" />
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="261.0" minWidth="10.0" prefWidth="200.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="261.0" minWidth="10.0" prefWidth="200.0" />
|
||||||
</columnConstraints>
|
</columnConstraints>
|
||||||
<rowConstraints>
|
<rowConstraints>
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
@ -17,17 +19,27 @@
|
|||||||
<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 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>
|
</rowConstraints>
|
||||||
<children>
|
<children>
|
||||||
<Label text="Voller Name: " />
|
<Label text="Name" />
|
||||||
<Label text="Handynummer: " GridPane.rowIndex="1" />
|
<Label text="Handynummer" GridPane.rowIndex="1" />
|
||||||
<Label prefWidth="95.0" text="Passwort: " GridPane.rowIndex="2" />
|
<Label prefWidth="95.0" text="Passwort: " GridPane.rowIndex="2" />
|
||||||
<Label text="Kind: " GridPane.rowIndex="3" />
|
<Label text="Kind:" GridPane.rowIndex="5" />
|
||||||
<Button mnemonicParsing="false" onAction="#OnRegistrationButton" prefHeight="26.0" prefWidth="90.0" text="Abschicken" translateX="100.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
<Label text="Straße" GridPane.rowIndex="3" />
|
||||||
<PasswordField fx:id="pfPassword" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
<Label text="Ort" GridPane.rowIndex="4" />
|
||||||
<TextField fx:id="tfName" GridPane.columnIndex="1" />
|
<Button mnemonicParsing="false" onAction="#OnRegistrationButton" prefHeight="26.0" prefWidth="90.0" text="Abschicken" translateX="100.0" GridPane.columnIndex="1" GridPane.rowIndex="7" />
|
||||||
<TextField fx:id="tfPhone" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<PasswordField fx:id="pfPassword" promptText="Passwort" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
<TextField fx:id="tfChild" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
<TextField fx:id="tfName" promptText="Voller Name" GridPane.columnIndex="1" />
|
||||||
|
<TextField fx:id="tfPhone" promptText="Handynummer" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
|
<TextField fx:id="tfChild" promptText="Kind" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||||
|
<TextField GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||||
|
<TextField fx:id="tfStreet" prefWidth="254.0" promptText="Straße" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||||
|
<TextField fx:id="tfHouseNumber" prefWidth="123.0" promptText="Hausnummer" GridPane.columnIndex="2" GridPane.rowIndex="3"/>
|
||||||
|
<TextField fx:id="tfPostalCode" promptText="Postleitzahl" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||||
|
<TextField fx:id="tfCity" promptText="Ort" GridPane.columnIndex="2" GridPane.rowIndex="4" />
|
||||||
|
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
|
Loading…
Reference in New Issue
Block a user