From 5880dbe88947228a28561e5ec40f35ee5ece764d Mon Sep 17 00:00:00 2001 From: rxdps93 <> Date: Wed, 24 Apr 2019 09:54:51 -0400 Subject: [PATCH] Improved log in; Added placeholder tab for administrative tasks (switching users, etc.) --- README.md | 4 +-- .../dom/freeman/components/InitialWindow.java | 10 ++++-- .../com/dom/freeman/components/MainPanel.java | 6 ++-- .../dom/freeman/components/MainWindow.java | 9 ++++++ .../freeman/components/admin/AdminPanel.java | 32 +++++++++++++++++++ .../components/users/UserControlPanel.java | 24 -------------- .../java/com/dom/freeman/utils/Utility.java | 5 +++ 7 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/dom/freeman/components/admin/AdminPanel.java diff --git a/README.md b/README.md index 1703eec..093312c 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ My intent is to develop a system comprised of four major components: ## Tentative Feature Timing #### Now - [x] Ability to manage expired items -- [ ] Require users to log in -- [ ] Give users a password +- [x] Require users to log in +- [x] Give users a password - [ ] Allow switching users - [ ] Make permissions actually do something - [ ] If the current user does not have permissions, allow temporary permission for one specific action granted by someone with permission diff --git a/src/main/java/com/dom/freeman/components/InitialWindow.java b/src/main/java/com/dom/freeman/components/InitialWindow.java index c376de6..dd263bf 100644 --- a/src/main/java/com/dom/freeman/components/InitialWindow.java +++ b/src/main/java/com/dom/freeman/components/InitialWindow.java @@ -18,6 +18,8 @@ import com.googlecode.lanterna.gui2.TextBox; import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.gui2.WindowListener; +import com.googlecode.lanterna.gui2.dialogs.MessageDialogBuilder; +import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.gui2.GridLayout.Alignment; @@ -66,11 +68,15 @@ private void configureContent() { buttonPanel.addComponent(new Button("Submit", new Runnable() { @Override public void run() { - if (pass.getText().equals(Utility.METHODS.getUserByDisplayName(users.getSelectedItem()).getPassword())) { + + if (Utility.METHODS.validateUser(pass.getText(), users.getSelectedItem())) { Global.OBJECTS.setCurrentUser(Utility.METHODS.getUserByDisplayName(users.getSelectedItem())); close(); } else { - System.out.println("INVALID"); + new MessageDialogBuilder().setTitle("Unable to log in") + .setText("The entered password does not match the one stored for the selected user.") + .setExtraWindowHints(Arrays.asList(Hint.CENTERED)) + .addButton(MessageDialogButton.OK).build().showDialog(getTextGUI()); } } })); diff --git a/src/main/java/com/dom/freeman/components/MainPanel.java b/src/main/java/com/dom/freeman/components/MainPanel.java index 7d0d3c2..4c4a8fb 100644 --- a/src/main/java/com/dom/freeman/components/MainPanel.java +++ b/src/main/java/com/dom/freeman/components/MainPanel.java @@ -30,7 +30,8 @@ public class MainPanel extends Panel { "MANAGE TAGS", "MANAGE TYPES", "MANAGE USERS", - "TRANSACTION LOGS" + "TRANSACTION LOGS", + "OTHER" }; private final String[] buttons = { @@ -39,7 +40,8 @@ public class MainPanel extends Panel { "F3", "F4", "F5", - "F6" + "F6", + "F7" }; public MainPanel(ViewPanel initialComponent) { diff --git a/src/main/java/com/dom/freeman/components/MainWindow.java b/src/main/java/com/dom/freeman/components/MainWindow.java index c47eeb5..0904426 100644 --- a/src/main/java/com/dom/freeman/components/MainWindow.java +++ b/src/main/java/com/dom/freeman/components/MainWindow.java @@ -3,6 +3,7 @@ import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; +import com.dom.freeman.components.admin.AdminPanel; import com.dom.freeman.components.dashboard.DashboardPanel; import com.dom.freeman.components.inventory.InventoryPanel; import com.dom.freeman.components.tags.TagPanel; @@ -28,6 +29,7 @@ public class MainWindow extends BasicWindow { private ViewPanel typePanel; private ViewPanel userPanel; private ViewPanel transactionPanel; + private ViewPanel adminPanel; public MainWindow() { super(); @@ -51,6 +53,7 @@ private void configureContent() { this.typePanel = new TypePanel(new LinearLayout()); this.userPanel = new UserPanel(new GridLayout(3)); this.transactionPanel = new TransactionPanel(new LinearLayout()); + this.adminPanel = new AdminPanel(); this.setComponent(new MainPanel(new BorderLayout(), this.dashboardPanel)); this.setHints(Arrays.asList(Hint.EXPANDED, Hint.FIXED_POSITION)); @@ -98,6 +101,12 @@ public void onInput(Window basePane, KeyStroke keyStroke, AtomicBoolean deliverE setFocusedInteractable(transactionPanel.getPrimaryInteractable()); } break; + case F7: + if (!getMainComponent().getCurrentComponent().getTrigger().equals(KeyType.F7)) { + getMainComponent().setView(adminPanel, 6); + setFocusedInteractable(adminPanel.getPrimaryInteractable()); + } + break; default: break; } diff --git a/src/main/java/com/dom/freeman/components/admin/AdminPanel.java b/src/main/java/com/dom/freeman/components/admin/AdminPanel.java new file mode 100644 index 0000000..b4d1053 --- /dev/null +++ b/src/main/java/com/dom/freeman/components/admin/AdminPanel.java @@ -0,0 +1,32 @@ +package com.dom.freeman.components.admin; + +import com.dom.freeman.components.ViewPanel; +import com.googlecode.lanterna.gui2.Interactable; +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.LayoutManager; +import com.googlecode.lanterna.input.KeyType; + +public class AdminPanel extends ViewPanel { + + private Interactable interactable; + + public AdminPanel() { + super(KeyType.F7); + this.configureContent(); + } + + public AdminPanel(LayoutManager layoutManager) { + super(layoutManager, KeyType.F7); + this.configureContent(); + } + + private void configureContent() { + + this.addComponent(new Label("Hello")); + } + + @Override + public Interactable getPrimaryInteractable() { + return this.interactable; + } +} diff --git a/src/main/java/com/dom/freeman/components/users/UserControlPanel.java b/src/main/java/com/dom/freeman/components/users/UserControlPanel.java index ddb2dd7..b0cc172 100644 --- a/src/main/java/com/dom/freeman/components/users/UserControlPanel.java +++ b/src/main/java/com/dom/freeman/components/users/UserControlPanel.java @@ -4,7 +4,6 @@ import com.dom.freeman.components.users.dialog.AddUserDialog; import com.dom.freeman.utils.Global; -import com.dom.freeman.utils.Utility; import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.Button; import com.googlecode.lanterna.gui2.GridLayout; @@ -12,7 +11,6 @@ import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.RadioBoxList; import com.googlecode.lanterna.gui2.Window.Hint; -import com.googlecode.lanterna.gui2.dialogs.ActionListDialogBuilder; public class UserControlPanel extends Panel { @@ -67,28 +65,6 @@ public void run() { } })); - options.addComponent(new Button("Switch Current User", new Runnable() { - @Override - public void run() { - // TODO: SWITCH THROUGH TEST ACCOUNTS FOR PERMISSIONS TESTING, REMOVE EVENTUALLY - new ActionListDialogBuilder().setTitle("Switch Current User") - .addAction("Developer: rxdps93" , new Runnable() { - @Override - public void run() { - Global.OBJECTS.setCurrentUser(Utility.METHODS.getUserById("de6274bd-ad65-47b3-8e14-0c6f1c90504a")); - Global.OBJECTS.getMainWindow().getMainComponent().updateCurrentUser(); - } - }) - .addAction("Administrator: mr. admin", new Runnable() { - @Override - public void run() { - Global.OBJECTS.setCurrentUser(Utility.METHODS.getUserById("92d5b2a8-2712-4687-9c8c-558fb2111da3")); - Global.OBJECTS.getMainWindow().getMainComponent().updateCurrentUser(); - } - }).build().showDialog(Global.OBJECTS.getMainWindow().getTextGUI()); - } - })); - return options; } diff --git a/src/main/java/com/dom/freeman/utils/Utility.java b/src/main/java/com/dom/freeman/utils/Utility.java index aabcab3..0d17a50 100644 --- a/src/main/java/com/dom/freeman/utils/Utility.java +++ b/src/main/java/com/dom/freeman/utils/Utility.java @@ -73,6 +73,11 @@ public List getTagsByItem(Item item) { return tags; } + + public boolean validateUser(String enteredPassword, String displayName) { + + return enteredPassword.equals(this.getUserByDisplayName(displayName).getPassword()); + } public Map itemTypeCount(List items) {