Class UserSession

java.lang.Object
com.example.cab302project.UserSession

public class UserSession extends Object
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 Type
    Method
    Description
    Retrieves the current active session.
    Gets the user data associated with the current session.
    static boolean
    Helper method to determine if the logged-in user prefers Dark Mode.
    static boolean
    Helper method to determine if the currently logged-in user has police permissions.
    static void
    login(User user)
    Initializes a new global session upon successful authentication.
    static void
    Terminates the current session by clearing the global instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • login

      public static void login(User user)
      Initializes a new global session upon successful authentication.
      Parameters:
      user - The User object to associate with the new session.
    • getInstance

      public static UserSession getInstance()
      Retrieves the current active session.
      Returns:
      The current UserSession instance, or null if no user is logged in.
    • getUser

      public User getUser()
      Gets the user data associated with the current session.
      Returns:
      The current User object.
    • 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.POLICE officer; false otherwise.