Login Validate geändert und für javaFx angepasst
This commit is contained in:
parent
2fe71cbe7e
commit
2f3f6a11f3
@ -1,5 +1,7 @@
|
|||||||
package com.example.vpr_javafx;
|
package com.example.vpr_javafx;
|
||||||
|
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -252,9 +254,8 @@ public class Data {
|
|||||||
* @return boolean inputValid
|
* @return boolean inputValid
|
||||||
* @author Kevin Maier
|
* @author Kevin Maier
|
||||||
*/
|
*/
|
||||||
private boolean validateData(String password, String phoneNumber)
|
public boolean validateData(String password, String phoneNumber)
|
||||||
{
|
{
|
||||||
boolean inputValid = false;
|
|
||||||
boolean phoneNumberMatchFound;
|
boolean phoneNumberMatchFound;
|
||||||
boolean passwordMatchFound;
|
boolean passwordMatchFound;
|
||||||
boolean phoneNumberValid = false;
|
boolean phoneNumberValid = false;
|
||||||
@ -263,16 +264,12 @@ public class Data {
|
|||||||
Pattern phoneNumberPattern = Pattern.compile("[0-9]*");
|
Pattern phoneNumberPattern = Pattern.compile("[0-9]*");
|
||||||
Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$");
|
Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$");
|
||||||
|
|
||||||
Scanner reader = new Scanner(System.in);
|
if (password.isEmpty() || phoneNumber.isEmpty())
|
||||||
|
|
||||||
while(password.isEmpty() || phoneNumber.isEmpty())
|
|
||||||
{
|
{
|
||||||
System.out.println("Login fehlgeschlagen. Eingabe ist leer, versuchen Sie es erneut.");
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
System.out.println("");
|
alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
|
||||||
System.out.print("Telefonnummer: ");
|
alert.show();
|
||||||
phoneNumber = reader.nextLine();
|
return false;
|
||||||
System.out.print("Passwort: ");
|
|
||||||
password = reader.nextLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
|
Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber);
|
||||||
@ -281,36 +278,35 @@ public class Data {
|
|||||||
phoneNumberMatchFound = phoneNumberMatcher.find();
|
phoneNumberMatchFound = phoneNumberMatcher.find();
|
||||||
passwordMatchFound = passwordMatcher.find();
|
passwordMatchFound = passwordMatcher.find();
|
||||||
|
|
||||||
while (!inputValid) {
|
if (!phoneNumberMatchFound || phoneNumber.length() >= 15)
|
||||||
if (!phoneNumberMatchFound || phoneNumber.length() != 15) {
|
{
|
||||||
System.out.println("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
System.out.println("");
|
alert.setContentText("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide.");
|
||||||
System.out.print("Telefonnummer: ");
|
alert.show();
|
||||||
phoneNumber = reader.nextLine();
|
return false;
|
||||||
System.out.print("Passwort: ");
|
}
|
||||||
password = reader.nextLine();
|
else
|
||||||
} else {
|
{
|
||||||
phoneNumberValid = true;
|
phoneNumberValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passwordMatchFound || password.length() < 6 || password.length() > 20) {
|
if (!passwordMatchFound || password.length() <8)
|
||||||
System.out.println("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide.");
|
{
|
||||||
System.out.println("");
|
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||||
System.out.print("Telefonnummer: ");
|
alert.setContentText("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide.");
|
||||||
phoneNumber = reader.nextLine();
|
alert.show();
|
||||||
System.out.print("Passwort: ");
|
return false;
|
||||||
password = reader.nextLine();
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
passwordValid = true;
|
passwordValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phoneNumberValid && passwordValid) {
|
return phoneNumberValid && passwordValid;
|
||||||
inputValid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return inputValid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method changes the orders.txt file by removing canceled orders
|
* The method changes the orders.txt file by removing canceled orders
|
||||||
*
|
*
|
||||||
|
@ -70,36 +70,31 @@ public class HelloController {
|
|||||||
{
|
{
|
||||||
LoginDatei file = new LoginDatei("user.txt");
|
LoginDatei file = new LoginDatei("user.txt");
|
||||||
HashMap<String, String> users = file.readFile();
|
HashMap<String, String> users = file.readFile();
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
|
|
||||||
if (users.containsKey(tfPhone.getText()))
|
String phoneNumber = tfPhone.getText();
|
||||||
|
String password = pfPassword.getText();
|
||||||
|
|
||||||
|
Data data = new Data("user.txt");
|
||||||
|
boolean inputValid = data.validateData(password, phoneNumber);
|
||||||
|
|
||||||
|
if (users.containsKey(phoneNumber) && inputValid)
|
||||||
{
|
{
|
||||||
if (users.containsValue(pfPassword.getText()))
|
if (users.get(phoneNumber).equals(password))
|
||||||
{
|
{
|
||||||
Parent root = FXMLLoader.load(getClass().getResource("MenuSelect-view.fxml"));
|
Parent root = FXMLLoader.load(getClass().getResource("MenuSelect-view.fxml"));
|
||||||
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
|
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
|
||||||
scene = new Scene(root);
|
scene = new Scene(root);
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
FillLabels();
|
||||||
else
|
|
||||||
{
|
|
||||||
alert.setContentText("Falsche Werte");
|
|
||||||
alert.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
alert.setContentText("Falsche Werte");
|
|
||||||
alert.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void FillLabels() {
|
protected void FillLabels() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<String> menu = Files.readAllLines(Paths.get("menue.txt"));
|
List<String> menu = Files.readAllLines(Paths.get("menue.txt"));
|
||||||
|
|
||||||
for (int i = 0; i < menu.size(); i++)
|
for (int i = 0; i < menu.size(); i++)
|
||||||
@ -111,87 +106,68 @@ public class HelloController {
|
|||||||
|
|
||||||
String dayMenu = dish+"\n"+sideDish;
|
String dayMenu = dish+"\n"+sideDish;
|
||||||
|
|
||||||
if (i == 0)
|
switch (i) {
|
||||||
{
|
case 0:
|
||||||
lMonH1.setText(dayMenu);
|
lMonH1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 1)
|
case 1:
|
||||||
{
|
|
||||||
lMonD1.setText(dayMenu);
|
lMonD1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 2)
|
case 2:
|
||||||
{
|
|
||||||
lMonH2.setText(dayMenu);
|
lMonH2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 3)
|
case 3:
|
||||||
{
|
|
||||||
lMonD2.setText(dayMenu);
|
lMonD2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 4)
|
case 4:
|
||||||
{
|
|
||||||
lTueH1.setText(dayMenu);
|
lTueH1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 5)
|
case 5:
|
||||||
{
|
|
||||||
lTueD1.setText(dayMenu);
|
lTueD1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 6)
|
case 6:
|
||||||
{
|
|
||||||
lTueH2.setText(dayMenu);
|
lTueH2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 7)
|
case 7:
|
||||||
{
|
|
||||||
lTueD2.setText(dayMenu);
|
lTueD2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 8)
|
case 8:
|
||||||
{
|
|
||||||
lWednH1.setText(dayMenu);
|
lWednH1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 9)
|
case 9:
|
||||||
{
|
|
||||||
lWednD1.setText(dayMenu);
|
lWednD1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 10)
|
case 10:
|
||||||
{
|
|
||||||
lWednH2.setText(dayMenu);
|
lWednH2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 11)
|
case 11:
|
||||||
{
|
|
||||||
lWednD2.setText(dayMenu);
|
lWednD2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 12)
|
case 12:
|
||||||
{
|
|
||||||
lThurH1.setText(dayMenu);
|
lThurH1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 13)
|
case 13:
|
||||||
{
|
|
||||||
lThurD1.setText(dayMenu);
|
lThurD1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 14)
|
case 14:
|
||||||
{
|
|
||||||
lThurH2.setText(dayMenu);
|
lThurH2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 15)
|
case 15:
|
||||||
{
|
|
||||||
lThurD2.setText(dayMenu);
|
lThurD2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 16)
|
case 16:
|
||||||
{
|
|
||||||
lFriH1.setText(dayMenu);
|
lFriH1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 17)
|
case 17:
|
||||||
{
|
|
||||||
lFriD1.setText(dayMenu);
|
lFriD1.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 18)
|
case 18:
|
||||||
{
|
|
||||||
lFriH2.setText(dayMenu);
|
lFriH2.setText(dayMenu);
|
||||||
}
|
break;
|
||||||
else if (i == 19)
|
case 19:
|
||||||
{
|
|
||||||
lFriD2.setText(dayMenu);
|
lFriD2.setText(dayMenu);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
@ -80,8 +80,4 @@ public class User {
|
|||||||
* @return a String with nameParent1, nameparent2, billAdress, phonenumber, nameChildren, password
|
* @return a String with nameParent1, nameparent2, billAdress, phonenumber, nameChildren, password
|
||||||
* @author Madeleine Vigier
|
* @author Madeleine Vigier
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return nameParent1 + ";" + nameParent2 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
user.txt
4
user.txt
@ -1,2 +1,2 @@
|
|||||||
Felix Düsterhaus;Sabine Gubitz;Detmolderstrasse 101,33102 Paderborn;1234567;Lisa,Peter;12345
|
Felix Düsterhaus;Sabine Gubitz;Detmolderstrasse 101,33102 Paderborn;1234567;Lisa,Peter;12345678A
|
||||||
Kevin Pfannenstiel;Marlene Pfannenstiel;Fürstenallee 30, 33102 Paderborn;7654321;Anton;12345
|
Kevin Pfannenstiel;Marlene Pfannenstiel;Fürstenallee 30, 33102 Paderborn;7654321;Anton;12345678B
|
||||||
|
Loading…
Reference in New Issue
Block a user