diff --git a/src/main/java/com/application/DB/Account_handler.java b/src/main/java/com/application/DB/Account_handler.java index 10dd3e7e2330eba910ffe1563f17e1b307c5e881..2c05fa0b49d607f0a4a593f904c51553f0150a71 100644 --- a/src/main/java/com/application/DB/Account_handler.java +++ b/src/main/java/com/application/DB/Account_handler.java @@ -14,7 +14,7 @@ public class Account_handler { public static void getAccount(String username, String password) throws Exception { // Sqlstatement - final String sqlStatement = "SELECT Username, Admin, Phone_no " + + final String sqlStatement = "SELECT Username, Admin, Phone_no, First_name, Last_name " + "FROM " + PROJECT_ID + "." + LOCATION_ID + "." + USERS_TABLE_NAME + " " + "WHERE Username = " + '"' + username + '"' + " " + "AND Password = " + '"' + password+ '"'; @@ -30,14 +30,19 @@ public class Account_handler { if (row.get("Username").getValue().equals(username)) { LogoBar.getLogin().setText(username); setUserName(username); - } - - if (!row.get("Phone_no").isNull()) { - setPhoneNo(row.get("Phone_no").getStringValue()); - } - if (row.get("Admin").getBooleanValue()) { - setIsAdmin(true); + if (!row.get("Phone_no").isNull()) { + setPhoneNo(row.get("Phone_no").getStringValue()); + } + if (!row.get("First_name").isNull()) { + setFirstName(row.get("First_name").getStringValue()); + } + if (!row.get("Last_name").isNull()) { + setLastName(row.get("Last_name").getStringValue()); + } + if (!row.get("Admin").isNull()) { + setIsAdmin(row.get("Admin").getBooleanValue()); + } } } } else { diff --git a/src/main/java/com/application/DB/Constants.java b/src/main/java/com/application/DB/Constants.java index a026f5182dd8413034e2a6212c4fcdfd4fd0ce4e..75ae0f2f28778d262908484973934d77e058c6d5 100644 --- a/src/main/java/com/application/DB/Constants.java +++ b/src/main/java/com/application/DB/Constants.java @@ -36,6 +36,8 @@ public class Constants { // Account constants private static boolean isAdmin = false; + private static String firstName; + private static String lastName; private static String userName; private static String phoneNo; @@ -62,4 +64,20 @@ public class Constants { public static void setIsAdmin(boolean isAdmin) { Constants.isAdmin = isAdmin; } + + public static String getFirstName() { + return firstName; + } + + public static void setFirstName(String firstName) { + Constants.firstName = firstName; + } + + public static String getLastName() { + return lastName; + } + + public static void setLastName(String lastName) { + Constants.lastName = lastName; + } } diff --git a/src/main/java/com/application/GUI/PopUpWindows/LoginPopup.java b/src/main/java/com/application/GUI/PopUpWindows/LoginPopup.java index 4db9e178b09cbd6efeb456db05ef1bbd7f048376..2e28bb1277500b785182163a48089f4b30da4edb 100644 --- a/src/main/java/com/application/GUI/PopUpWindows/LoginPopup.java +++ b/src/main/java/com/application/GUI/PopUpWindows/LoginPopup.java @@ -18,6 +18,8 @@ import java.security.SecureRandom; import java.util.Arrays; import static com.application.DB.Account_handler.getAccount; +import static com.application.DB.Constants.*; +import static com.application.GUI.Panes.LogoBar.getLogin; public class LoginPopup { @@ -33,6 +35,7 @@ public class LoginPopup { Label passwordLabel = new Label("Password:"); TextField userNameTextField = new TextField(); + getPasswordTextField().clear(); Button closeButton = new Button("Close"); Button loginButton = new Button("Login"); @@ -56,7 +59,7 @@ public class LoginPopup { getAccount(userNameTextField.getText(),hashedPasswordString.toString()); - if(!LogoBar.getLogin().getText().equals("Login")){ + if(!getLogin().getText().equals("Login")){ window.close(); } @@ -85,7 +88,55 @@ public class LoginPopup { Stage window = new Stage(); window.initModality(Modality.APPLICATION_MODAL); - window.setTitle("Login window"); + window.setTitle("Admin window"); + + Label usernameLabel = new Label("Username: "); + TextField usernameTextfield = new TextField(); + usernameTextfield.setText(getUserName()); + usernameTextfield.setEditable(false); + + Button addUser = new Button("Add User"); + Button deleteUser = new Button("Delete User"); + Button logout = new Button("Logout"); + + addUser.setOnAction(event -> { + window.close(); + adminAddUser(); + }); + deleteUser.setOnAction(event -> { + window.close(); + adminDeleteUser(); + }); + logout.setOnAction(event -> { + window.close(); + logout(); + }); + + + VBox layout = new VBox(10); + layout.setAlignment(Pos.CENTER); + layout.getChildren().addAll(usernameLabel, usernameTextfield, addUser, deleteUser, logout); + + Scene scene = new Scene(layout, 500, 300); + scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm()); + window.setScene(scene); + window.showAndWait(); + } + + public static void adminAddUser(){ + + Stage window = new Stage(); + window.initModality(Modality.APPLICATION_MODAL); + window.setTitle("Admin window"); + + Label firstNameLabel = new Label("First Name: "); + Label lastNameLabel = new Label("Last Name: "); + Label phoneNoLabel = new Label("Phone No: "); + Label username = new Label("Username: "); + Label passwordFirst = new Label("Password"); + + + VBox layout = new VBox(10); @@ -98,11 +149,20 @@ public class LoginPopup { window.showAndWait(); } - public static void userPopup(){ + public static void adminDeleteUser(){ Stage window = new Stage(); window.initModality(Modality.APPLICATION_MODAL); - window.setTitle("Login window"); + window.setTitle("Admin window"); + + Label firstNameLabel = new Label("First Name: "); + Label lastNameLabel = new Label("Last Name: "); + Label phoneNoLabel = new Label("Phone No: "); + Label username = new Label("Username: "); + Label passwordFirst = new Label("Password"); + + + VBox layout = new VBox(10); @@ -115,6 +175,43 @@ public class LoginPopup { window.showAndWait(); } + public static void logout(){ + getLogin().setText("Login"); + setFirstName(""); + setLastName(""); + setIsAdmin(false); + setPhoneNo(""); + setUserName(""); + } + + public static void userPopup(){ + + Stage window = new Stage(); + window.initModality(Modality.APPLICATION_MODAL); + window.setTitle("User window"); + + + Label nameLabel = new Label("Name: "); + Label phoneNoLabel = new Label("Phone no: "); + + TextField nameTextfield = new TextField(); + TextField phoneNoTextField = new TextField(); + + nameTextfield.setText(getFirstName() + " " + getLastName()); + phoneNoTextField.setText(getPhoneNo()); + + Button logout = new Button("Logout"); + + VBox layout = new VBox(10); + layout.setAlignment(Pos.CENTER); + layout.getChildren().addAll(nameLabel, nameTextfield, phoneNoLabel, phoneNoTextField, logout); + + Scene scene = new Scene(layout, 500, 300); + scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm()); + window.setScene(scene); + window.showAndWait(); + } + public static PasswordField getPasswordTextField() { return PASSWORD_TEXT_FIELD; } diff --git a/target/classes/com/application/DB/Account_handler.class b/target/classes/com/application/DB/Account_handler.class index 254fefbc8b16860ea8ebc924d879720d5c4da3fc..8d513275eda4d202e46c120ea5da851ea1fba4e1 100644 Binary files a/target/classes/com/application/DB/Account_handler.class and b/target/classes/com/application/DB/Account_handler.class differ diff --git a/target/classes/com/application/DB/Constants.class b/target/classes/com/application/DB/Constants.class index 14dbc461da2178a2135d25751ff437e29ad98f62..f9229ec0ebccb95510e2f7694f75caeb87e56e94 100644 Binary files a/target/classes/com/application/DB/Constants.class and b/target/classes/com/application/DB/Constants.class differ diff --git a/target/classes/com/application/GUI/PopUpWindows/LoginPopup.class b/target/classes/com/application/GUI/PopUpWindows/LoginPopup.class index c0bfec4e092c91274be6d9220d72a0f18defb406..3f8a75275aab99173bb5eb93f608c03a1989df38 100644 Binary files a/target/classes/com/application/GUI/PopUpWindows/LoginPopup.class and b/target/classes/com/application/GUI/PopUpWindows/LoginPopup.class differ