java.lang.Object
com.example.cab302project.UserSession
Manages the global authentication state for the application.
This class uses a Singleton-like pattern to store the currently logged-in
User.
It provides centralized access to user preferences (like Dark Mode) and
permission levels (like Police status) across all UI controllers.-
Method Summary
Modifier and TypeMethodDescriptionstatic UserSessionRetrieves the current active session.getUser()Gets the user data associated with the current session.static booleanHelper method to determine if the logged-in user prefers Dark Mode.static booleanisPolice()Helper method to determine if the currently logged-in user has police permissions.static voidInitializes a new global session upon successful authentication.static voidlogout()Terminates the current session by clearing the global instance.
-
Method Details
-
login
Initializes a new global session upon successful authentication.- Parameters:
user- TheUserobject to associate with the new session.
-
getInstance
Retrieves the current active session.- Returns:
- The current
UserSessioninstance, or null if no user is logged in.
-
getUser
Gets the user data associated with the current session.- Returns:
- The current
Userobject.
-
logout
public static void logout()Terminates the current session by clearing the global instance. This effectively logs the user out of the system. -
isDarkMode
public static boolean isDarkMode()Helper method to determine if the logged-in user prefers Dark Mode. Used by UI controllers to apply CSS styling.- Returns:
- true if a user is logged in and has Dark Mode enabled; false otherwise.
-
isPolice
public static boolean isPolice()Helper method to determine if the currently logged-in user has police permissions. This provides a shorthand way to check roles without accessing the User object directly.- Returns:
- true if the current user is a
UserType.POLICEofficer; false otherwise.
-