diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2a3281e..7a44909 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,17 @@ - + + + + + + + + + + @@ -125,6 +141,7 @@ - \ No newline at end of file diff --git a/database.db b/database.db index 84c0b26..b44a0a6 100644 Binary files a/database.db and b/database.db differ diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/AccountMgr.java b/src/main/java/com/bib/essensbestellungsverwaltung/AccountMgr.java index 349e1e3..37c045d 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/AccountMgr.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/AccountMgr.java @@ -17,6 +17,8 @@ import java.util.List; */ public class AccountMgr { + static User currentUser = null; + /** * creates a user with createUser(...) and adds its id to the 'worker' table * @param worker the worker to be created @@ -202,6 +204,32 @@ public class AccountMgr { String[] userD = {email,hashAndSalt(pw,salt)}; return Database.getSingleId("user",userH,userD); } + /** + * update password in User table + * @param password User + * @return update password + * @author Reshad Meher + */ + protected static long updatePassword( User password) { + + String[] pwH = {"password"}; + String[] pwD = {password.getPassword()}; + long updates = Database.update("user",pwH,pwD); + return updates; + } + /** + * update adress in User table + * @param address Adresss + * @return update Adrssse + * @author Reshad Meher + */ + protected static long updateAdreess(Address address ){ + String[] adH = {"stree","numbrt","plz","city"}; + String[] adD = {address.getStreet(),address.getNumber(),address.getPlz(),address.getCity()}; + long updates = Database.update("user",adH,adD); + return updates; + } + /** * checks if id is in worker table diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/ParentController.java b/src/main/java/com/bib/essensbestellungsverwaltung/ParentController.java index 9639516..07a58be 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/ParentController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/ParentController.java @@ -1,6 +1,78 @@ package com.bib.essensbestellungsverwaltung; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.Button; +import javafx.scene.layout.BorderPane; +import org.w3c.dom.events.MouseEvent; + +import java.io.IOException; + public class ParentController{ + @FXML + BorderPane contentView; + @FXML + Button essensplanButton; + @FXML + Button kinderButton; + @FXML + Button bestellungButton; + @FXML + Button einstellungenButton; + @FXML + public void initialize() { + changePage("menue-view.fxml"); + setButtonActive(essensplanButton); + } + + + @FXML + public void onEssensplanClick(MouseEvent mouseEvent) { + setButtonActive(essensplanButton); + changePage("menue-view.fxml"); + } + + @FXML + public void onKinderClick(MouseEvent mouseEvent) { + setButtonActive(kinderButton); + changePage("child-view.fxml"); + } + + @FXML + public void onBestellungClick(MouseEvent mouseEvent) { + setButtonActive(bestellungButton); + changePage("orderHistory-view.fxml"); + } + + @FXML + public void onEinstellungenClick(MouseEvent mouseEvent) { + setButtonActive(einstellungenButton); + changePage("SettingsMenue.fxml"); + } + + @FXML + public void onAusloggenClick(MouseEvent mouseEvent) throws IOException { + AccountMgr.currentUser = null; + StartViewApplication.changeScene("login-view.fxml"); + } + + private void changePage(String page) { + try { + Parent root = FXMLLoader.load(getClass().getResource(page)); + //contentView.setCenter(root); + } catch (IOException e) { + throw new RuntimeException(e); } + } + + private void setButtonActive(Button b) { + einstellungenButton.getStyleClass().remove("active"); + kinderButton.getStyleClass().remove("active"); + bestellungButton.getStyleClass().remove("active"); + essensplanButton.getStyleClass().remove("active"); + b.getStyleClass().add("active"); + } + +} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/SettingsController.java b/src/main/java/com/bib/essensbestellungsverwaltung/SettingsController.java new file mode 100644 index 0000000..b2839c0 --- /dev/null +++ b/src/main/java/com/bib/essensbestellungsverwaltung/SettingsController.java @@ -0,0 +1,144 @@ +package com.bib.essensbestellungsverwaltung; +/** + * @autor Reshad Meher + */ + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.TextField; + +import java.io.IOException; + +public class SettingsController { + + @FXML + private TextField tfOldPassword; + @FXML + private TextField tfNewPassword; + @FXML + private TextField tfConfirmNewPasword; + @FXML + private TextField tfPostCode; + @FXML + private TextField tfStreet; + @FXML + private TextField tfCity; + @FXML + private TextField tfHousNumber; + + Alert alert; + @FXML + private void onPasswordChangClick(){ + String oldPassword = tfOldPassword.getText(); + String newPassword = tfNewPassword.getText(); + String confirmNewPassword = tfConfirmNewPasword.getText(); + if(!oldPassword.isEmpty() && !newPassword.isEmpty() && !confirmNewPassword.isEmpty()){ + if(!newPassword.equals(confirmNewPassword)){ + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Passwort"); + alert.setHeaderText("Ihre neue Passwort und Bestätigung passt nicht. Nochmal versuchen"); + alert.showAndWait(); + }else { + User userPassword = new User(newPassword); + long UpdateUserPassword = AccountMgr.updatePassword(userPassword); + if (UpdateUserPassword > 0){ + alert.setTitle("Passwort"); + alert.setHeaderText("Ihre Passwort erfolgreich geändert"); + alert.showAndWait(); + } + else { + alert.setTitle("Passwort"); + alert.setHeaderText("nei"); + alert.showAndWait(); + } + } + + tfOldPassword.setText(""); + tfNewPassword.setText(""); + tfConfirmNewPasword.setText(""); + } + else { + if(oldPassword.isEmpty()){ + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Passwort"); + alert.setHeaderText("Ihre aktuelles Passwort ist leer."); + alert.showAndWait(); + }else if(newPassword.isEmpty()){ + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Passwort"); + alert.setHeaderText("Ihre neues Passwort ist leer."); + alert.showAndWait(); + }if(confirmNewPassword.isEmpty()){ + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Passwort"); + alert.setHeaderText("Ihre neue Passwort Bestätigung ist leer."); + alert.showAndWait(); + }else{ + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Passwort"); + alert.setHeaderText("Ihre Passwort wurde nicht geändert"); + alert.showAndWait(); + } + + } + } + + @FXML + private void onChangAdressClick(){ + String postCode = tfPostCode.getText(); + String street = tfStreet.getText(); + String city = tfCity.getText(); + String housNumber = tfHousNumber.getText(); + if (!postCode.isEmpty() && !street.isEmpty() && !city.isEmpty() && !housNumber.isEmpty()) { + Address userAdress = new Address(street,housNumber,postCode,city); + long UpdateUserAdress = AccountMgr.updateAdreess(userAdress); + if (UpdateUserAdress > 0) { + alert.setTitle("Adresse"); + alert.setHeaderText("Ihre Adresse erfolgreich geändert"); + alert.showAndWait(); + + tfPostCode.setText(""); + tfStreet.setText(""); + tfCity.setText(""); + tfHousNumber.setText(""); + } + + }else { + if (postCode.isEmpty()) { + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Adresse"); + alert.setHeaderText("Postleitzahl ist leer."); + alert.showAndWait(); + } else if (street.isEmpty()) { + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Adresse"); + alert.setHeaderText("Straß ist leer."); + alert.showAndWait(); + } else if (city.isEmpty()) { + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Adresse"); + alert.setHeaderText("Statd ist leer."); + alert.showAndWait(); + } else if (housNumber.isEmpty()) { + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Adresse"); + alert.setHeaderText("Hausnumer ist leer."); + alert.showAndWait(); + } else { + alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("Adresse"); + alert.setHeaderText("Ihre Adresse wurde nicht geändert"); + alert.showAndWait(); + } + } + } + @FXML + private void onLogOutBtClick() throws IOException{ + + FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("login-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 950,700); + StartViewApplication.primary.setScene(scene); + } +} diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java b/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java index 81c233a..d5dbe03 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/StartViewApplication.java @@ -7,6 +7,7 @@ package com.bib.essensbestellungsverwaltung; import javafx.application.Application; import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; @@ -14,10 +15,12 @@ import java.io.IOException; public class StartViewApplication extends Application { public static Stage primary; + public static boolean firstLaunch; @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("login-view.fxml")); - Scene scene = new Scene(fxmlLoader.load(), 950,700); + //FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource((firstLaunch) ? "signUp-view.fxml" : "login-view.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource((firstLaunch) ? "settingsMenue.fxml" : "settingsMenue.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 1220, 790); primary = stage; stage.setTitle("Essen Bestellung im Kindergarten"); stage.setScene(scene); @@ -25,6 +28,7 @@ public class StartViewApplication extends Application { } public static void main(String[] args) { + firstLaunch = Database.init(); Database.init(); Database.createDb(); Database.fillDb(); @@ -32,4 +36,9 @@ public class StartViewApplication extends Application { //Database.deleteSample(); launch(); } + + public static void changeScene(String scene) throws IOException{ + Parent p = FXMLLoader.load(StartViewApplication.class.getResource(scene)); + primary.getScene().setRoot(p); + } } \ No newline at end of file diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/User.java b/src/main/java/com/bib/essensbestellungsverwaltung/User.java index fb89351..2aea7c9 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/User.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/User.java @@ -28,6 +28,9 @@ public class User { this.email = email; this.address = address; } + public User (String password){ + this.password = password; + } public long getId() { return id; diff --git a/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml b/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml index 1023f4f..40a229d 100644 --- a/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml +++ b/src/main/resources/com/bib/essensbestellungsverwaltung/child-view.fxml @@ -2,9 +2,9 @@ - - - + + + @@ -13,88 +13,63 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + - - - - - + + + - - - - - + + + + - - + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +