diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/AccountMgr.java b/src/main/java/com/bib/essensbestellungsverwaltung/AccountMgr.java index 349e1e3..6e16b8d 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 diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/ConsoleMain.java b/src/main/java/com/bib/essensbestellungsverwaltung/ConsoleMain.java index 189760f..cde3844 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/ConsoleMain.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/ConsoleMain.java @@ -7,7 +7,7 @@ import java.util.Scanner; * @author Malte Schulze Hobeling */ public class ConsoleMain { - static User currentUser = null; + //static User currentUser = null; static boolean running = true; public static void main(String[] args) { boolean firstRun = Database.init(); @@ -18,12 +18,12 @@ public class ConsoleMain { } AccountMgr.getPrice(); while (running){ - if(currentUser == null){ + if(AccountMgr.currentUser == null){ defaultMenu(); }else{ - if(currentUser.getClass().getSimpleName().equals("Worker")){ + if(AccountMgr.currentUser.getClass().getSimpleName().equals("Worker")){ adminMenu(); - }else if(currentUser.getClass().getSimpleName().equals("Parent")){ + }else if(AccountMgr.currentUser.getClass().getSimpleName().equals("Parent")){ parentMenu(); } } @@ -42,7 +42,7 @@ public class ConsoleMain { switch (selection) { case "0" -> running = false; case "1" -> { - currentUser = ConsoleLib.loginPrompt(); + AccountMgr.currentUser = ConsoleLib.loginPrompt(); } case "2" -> ConsoleLib.showFood_planPrompt(); case "3" -> ConsoleLib.createParentPrompt(); @@ -71,12 +71,12 @@ public class ConsoleMain { String selection = sc.nextLine(); switch (selection) { case "0" -> { - currentUser = null; + AccountMgr.currentUser = null; } case "1" -> ConsoleLib.createWorkerPrompt(); case "2" -> ConsoleLib.createParentPrompt(); - case "3" -> ConsoleLib.createChildPrompt(String.valueOf(currentUser.getId())); - case "4" -> ConsoleLib.matchParentChildPrompt(String.valueOf(currentUser.getId())); + case "3" -> ConsoleLib.createChildPrompt(String.valueOf(AccountMgr.currentUser.getId())); + case "4" -> ConsoleLib.matchParentChildPrompt(String.valueOf(AccountMgr.currentUser.getId())); case "5" -> ConsoleLib.createFoodPrompt(); case "6" -> ConsoleLib.createFood_planPrompt(); case "7" -> ConsoleLib.showFood_planPrompt(); @@ -102,9 +102,9 @@ public class ConsoleMain { String selection = sc.nextLine(); switch (selection) { case "0" -> { - currentUser = null; + AccountMgr.currentUser = null; } - case "3" -> ConsoleLib.createChildPrompt(String.valueOf(currentUser.getId())); + case "3" -> ConsoleLib.createChildPrompt(String.valueOf(AccountMgr.currentUser.getId())); case "6" -> ConsoleLib.tablePrompt(); case "7" -> ConsoleLib.showFood_planPrompt(); case "8" -> ConsoleLib.createFood_selectionPrompt(); diff --git a/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java b/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java index 87b5479..223b162 100644 --- a/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java +++ b/src/main/java/com/bib/essensbestellungsverwaltung/LoginController.java @@ -19,15 +19,19 @@ public class LoginController { @FXML private PasswordField pfPassword; - HashMap benutzerMap = new HashMap(); @FXML protected void onBtLoginClick() throws IOException { - benutzerMap.put("Reshad","1234"); String email = tfEmail.getText(); String password = pfPassword.getText(); - if(benutzerMap.containsKey(email) && benutzerMap.containsValue(password)){ - // if user is worker: StartViewApplication.changeScene("workerMenu-view.fxml"); - StartViewApplication.changeScene("parentMenu-view.fxml"); + long loginPruefen = AccountMgr.login(email,password); + if(loginPruefen > 0){ + AccountMgr.currentUser = AccountMgr.getUserById(loginPruefen); + if(AccountMgr.currentUser.getClass().getSimpleName().equals("Worker")){ + StartViewApplication.changeScene("workerMenu-view.fxml"); + }else{ + StartViewApplication.changeScene("parentMenu-view.fxml"); + } + }else { Alert alert = new Alert(Alert.AlertType.ERROR,"Email oder Passwort ist falsch"); alert.showAndWait();