Implement RBAC with login screen for admin and staff roles

- Add Role enum (ADMIN, STAFF) and UserSession singleton
- Add User model and UserDB with SHA2-256 authentication
- Add login screen (login-view.fxml + LoginController)
- Update main-layout-view.fxml: dynamic username/role labels, logout button
- Update MainLayoutController: hide Inventory/Suppliers/Product-Suppliers for STAFF, show username/role, handle logout
- Update PetShopApplication to start with login screen and initialize users table
- Update module-info.java to open/export auth package
This commit is contained in:
2026-02-21 13:27:50 -07:00
parent fb16da91e2
commit a12af3f0ee
10 changed files with 363 additions and 4 deletions

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox alignment="CENTER" prefHeight="400.0" prefWidth="380.0" spacing="16.0"
style="-fx-background-color: #2C3E50;"
xmlns="http://javafx.com/javafx/25"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.example.petshopdesktop.controllers.LoginController">
<padding>
<Insets bottom="40.0" left="50.0" right="50.0" top="40.0" />
</padding>
<children>
<Label text="🐾 Pet Shop Manager" textFill="WHITE">
<font>
<Font name="Comic Sans MS Bold" size="22.0" />
</font>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</Label>
<Label text="Username" textFill="#cccccc">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<TextField fx:id="txtUsername" promptText="Enter username"
style="-fx-background-color: #3d5166; -fx-text-fill: white; -fx-prompt-text-fill: #888; -fx-background-radius: 8; -fx-border-width: 0;">
<padding>
<Insets bottom="10.0" left="12.0" right="12.0" top="10.0" />
</padding>
<font>
<Font size="14.0" />
</font>
</TextField>
<Label text="Password" textFill="#cccccc">
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<PasswordField fx:id="txtPassword" promptText="Enter password"
style="-fx-background-color: #3d5166; -fx-text-fill: white; -fx-prompt-text-fill: #888; -fx-background-radius: 8; -fx-border-width: 0;">
<padding>
<Insets bottom="10.0" left="12.0" right="12.0" top="10.0" />
</padding>
<font>
<Font size="14.0" />
</font>
</PasswordField>
<Label fx:id="lblError" text="" textFill="#FF6B6B" wrapText="true">
<font>
<Font size="13.0" />
</font>
</Label>
<Button fx:id="btnLogin" mnemonicParsing="false" onAction="#btnLoginClicked"
prefWidth="280.0"
style="-fx-background-color: #FF6B6B; -fx-background-radius: 8; -fx-cursor: hand;"
text="Login" textFill="WHITE">
<font>
<Font name="System Bold" size="15.0" />
</font>
<padding>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</padding>
<VBox.margin>
<Insets top="8.0" />
</VBox.margin>
</Button>
</children>
</VBox>

View File

@@ -16,12 +16,12 @@
<Insets bottom="30.0" left="30.0" right="30.0" top="30.0" />
</padding>
<children>
<Label text="Name" textFill="WHITE">
<Label fx:id="lblUsername" text="Name" textFill="WHITE">
<font>
<Font name="Comic Sans MS Bold" size="30.0" />
</font>
</Label>
<Label text="Pet Store Manager" textFill="#ffe66d">
<Label fx:id="lblRole" text="Pet Store Manager" textFill="#ffe66d">
<font>
<Font name="Comic Sans MS Bold" size="16.0" />
</font>
@@ -106,6 +106,17 @@
<Insets bottom="12.0" left="12.0" right="45.0" top="12.0" />
</padding>
</Button>
<Button fx:id="btnLogout" mnemonicParsing="false" onAction="#btnLogoutClicked" prefWidth="250.0" style="-fx-background-color: #34495E; -fx-background-radius: 8; -fx-cursor: hand;" text="🚪 Logout" textFill="#cccccc">
<font>
<Font name="Comic Sans MS Bold" size="14.0" />
</font>
<padding>
<Insets bottom="12.0" left="12.0" right="94.0" top="12.0" />
</padding>
<VBox.margin>
<Insets top="20.0" />
</VBox.margin>
</Button>
</children>
</VBox>
</left>