Skip to content

Commit

Permalink
Improved log in; Added placeholder tab for administrative tasks (swit…
Browse files Browse the repository at this point in the history
…ching users, etc.)
  • Loading branch information
rxdps93 committed Apr 24, 2019
1 parent 8bf7c32 commit 5880dbe
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/dom/freeman/components/InitialWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}
}));
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/dom/freeman/components/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class MainPanel extends Panel {
"MANAGE TAGS",
"MANAGE TYPES",
"MANAGE USERS",
"TRANSACTION LOGS"
"TRANSACTION LOGS",
"OTHER"
};

private final String[] buttons = {
Expand All @@ -39,7 +40,8 @@ public class MainPanel extends Panel {
"F3",
"F4",
"F5",
"F6"
"F6",
"F7"
};

public MainPanel(ViewPanel initialComponent) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/dom/freeman/components/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@ public class MainWindow extends BasicWindow {
private ViewPanel typePanel;
private ViewPanel userPanel;
private ViewPanel transactionPanel;
private ViewPanel adminPanel;

public MainWindow() {
super();
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/dom/freeman/components/admin/AdminPanel.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

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;
import com.googlecode.lanterna.gui2.LayoutManager;
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 {

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/dom/freeman/utils/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public List<ItemTag> getTagsByItem(Item item) {

return tags;
}

public boolean validateUser(String enteredPassword, String displayName) {

return enteredPassword.equals(this.getUserByDisplayName(displayName).getPassword());
}

public Map<String, Integer> itemTypeCount(List<Item> items) {

Expand Down

0 comments on commit 5880dbe

Please sign in to comment.