moving currentUser to AccountMgr

moving to stable:
Reshad Meher:
login
This commit is contained in:
Malte Schulze Hobeling 2023-02-01 23:05:24 +01:00
parent 3643f44afb
commit d2df46eaa6
3 changed files with 21 additions and 15 deletions

View File

@ -17,6 +17,8 @@ import java.util.List;
*/ */
public class AccountMgr { public class AccountMgr {
static User currentUser = null;
/** /**
* creates a user with createUser(...) and adds its id to the 'worker' table * creates a user with createUser(...) and adds its id to the 'worker' table
* @param worker the worker to be created * @param worker the worker to be created

View File

@ -7,7 +7,7 @@ import java.util.Scanner;
* @author Malte Schulze Hobeling * @author Malte Schulze Hobeling
*/ */
public class ConsoleMain { public class ConsoleMain {
static User currentUser = null; //static User currentUser = null;
static boolean running = true; static boolean running = true;
public static void main(String[] args) { public static void main(String[] args) {
boolean firstRun = Database.init(); boolean firstRun = Database.init();
@ -18,12 +18,12 @@ public class ConsoleMain {
} }
AccountMgr.getPrice(); AccountMgr.getPrice();
while (running){ while (running){
if(currentUser == null){ if(AccountMgr.currentUser == null){
defaultMenu(); defaultMenu();
}else{ }else{
if(currentUser.getClass().getSimpleName().equals("Worker")){ if(AccountMgr.currentUser.getClass().getSimpleName().equals("Worker")){
adminMenu(); adminMenu();
}else if(currentUser.getClass().getSimpleName().equals("Parent")){ }else if(AccountMgr.currentUser.getClass().getSimpleName().equals("Parent")){
parentMenu(); parentMenu();
} }
} }
@ -42,7 +42,7 @@ public class ConsoleMain {
switch (selection) { switch (selection) {
case "0" -> running = false; case "0" -> running = false;
case "1" -> { case "1" -> {
currentUser = ConsoleLib.loginPrompt(); AccountMgr.currentUser = ConsoleLib.loginPrompt();
} }
case "2" -> ConsoleLib.showFood_planPrompt(); case "2" -> ConsoleLib.showFood_planPrompt();
case "3" -> ConsoleLib.createParentPrompt(); case "3" -> ConsoleLib.createParentPrompt();
@ -71,12 +71,12 @@ public class ConsoleMain {
String selection = sc.nextLine(); String selection = sc.nextLine();
switch (selection) { switch (selection) {
case "0" -> { case "0" -> {
currentUser = null; AccountMgr.currentUser = null;
} }
case "1" -> ConsoleLib.createWorkerPrompt(); case "1" -> ConsoleLib.createWorkerPrompt();
case "2" -> ConsoleLib.createParentPrompt(); case "2" -> ConsoleLib.createParentPrompt();
case "3" -> ConsoleLib.createChildPrompt(String.valueOf(currentUser.getId())); case "3" -> ConsoleLib.createChildPrompt(String.valueOf(AccountMgr.currentUser.getId()));
case "4" -> ConsoleLib.matchParentChildPrompt(String.valueOf(currentUser.getId())); case "4" -> ConsoleLib.matchParentChildPrompt(String.valueOf(AccountMgr.currentUser.getId()));
case "5" -> ConsoleLib.createFoodPrompt(); case "5" -> ConsoleLib.createFoodPrompt();
case "6" -> ConsoleLib.createFood_planPrompt(); case "6" -> ConsoleLib.createFood_planPrompt();
case "7" -> ConsoleLib.showFood_planPrompt(); case "7" -> ConsoleLib.showFood_planPrompt();
@ -102,9 +102,9 @@ public class ConsoleMain {
String selection = sc.nextLine(); String selection = sc.nextLine();
switch (selection) { switch (selection) {
case "0" -> { 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 "6" -> ConsoleLib.tablePrompt();
case "7" -> ConsoleLib.showFood_planPrompt(); case "7" -> ConsoleLib.showFood_planPrompt();
case "8" -> ConsoleLib.createFood_selectionPrompt(); case "8" -> ConsoleLib.createFood_selectionPrompt();

View File

@ -19,15 +19,19 @@ public class LoginController {
@FXML @FXML
private PasswordField pfPassword; private PasswordField pfPassword;
HashMap<String,String> benutzerMap = new HashMap<String,String>();
@FXML @FXML
protected void onBtLoginClick() throws IOException { protected void onBtLoginClick() throws IOException {
benutzerMap.put("Reshad","1234");
String email = tfEmail.getText(); String email = tfEmail.getText();
String password = pfPassword.getText(); String password = pfPassword.getText();
if(benutzerMap.containsKey(email) && benutzerMap.containsValue(password)){ long loginPruefen = AccountMgr.login(email,password);
// if user is worker: StartViewApplication.changeScene("workerMenu-view.fxml"); if(loginPruefen > 0){
StartViewApplication.changeScene("parentMenu-view.fxml"); AccountMgr.currentUser = AccountMgr.getUserById(loginPruefen);
if(AccountMgr.currentUser.getClass().getSimpleName().equals("Worker")){
StartViewApplication.changeScene("workerMenu-view.fxml");
}else{
StartViewApplication.changeScene("parentMenu-view.fxml");
}
}else { }else {
Alert alert = new Alert(Alert.AlertType.ERROR,"Email oder Passwort ist falsch"); Alert alert = new Alert(Alert.AlertType.ERROR,"Email oder Passwort ist falsch");
alert.showAndWait(); alert.showAndWait();