java.lang.Object
ai.tutor.cab302exceptionalhandlers.controller.UserSettingsController

public class UserSettingsController extends Object
Controls the user settings screen in the AI tutor application.

Allows users to update their username or password, view account statistics, log out, or terminate their account. Interacts with the database via UserDAO to update user details and uses SceneManager for navigation to other screens (e.g., chat, login, sign-up).

See Also:
  • Constructor Details

    • UserSettingsController

      public UserSettingsController(SQLiteConnection connection, User authenticatedUser) throws IllegalStateException, RuntimeException, SQLException
      Constructs a UserSettingsController with a database connection and user.

      Initializes the db connection, creates a UserDAO instance, and sets the currentUser whose settings will be managed. Throws an exception if the provided user is null.

      Parameters:
      connection - The SQLite database connection
      authenticatedUser - The currently authenticated user
      Throws:
      IllegalStateException - If the user is null
      RuntimeException - If unexpected errors occur during setup
      SQLException - If database initialization fails
  • Method Details

    • initialize

      public void initialize()
      Initializes the user settings screen’s UI components and event handlers.

      Sets up the username field (setupUsernameField()), back button (setupBackButton()), logout button (setupLogoutButton()), save button (setupSaveButton()), and terminate button (setupTerminateButton()). Called automatically by JavaFX when the FXML is loaded.

    • updateUsername

      public void updateUsername(String newUsername) throws IllegalArgumentException, SQLException
      Updates the user’s username if it has changed.

      Checks if the new username differs from the current one, ensures it’s not already taken using UserDAO.getUser(String), and updates the user in the database via UserDAO.updateUser(User). Sets usernameChanged to true if the update occurs.

      Parameters:
      newUsername - The new username to set
      Throws:
      IllegalArgumentException - If the username is already taken
      SQLException - If database operations fail
    • updatePassword

      public void updatePassword(String currentPassword, String newPassword) throws IllegalArgumentException, SecurityException, SQLException
      Updates the user’s password after verifying the current password.

      Validates the new password is not empty, verifies the current password using User.verifyPassword(String), hashes the new password with User.hashPassword(String), and updates the user in the database via UserDAO.updateUser(User). Sets passwordChanged to true if the update occurs.

      Parameters:
      currentPassword - The user’s current password for verification
      newPassword - The new password to set
      Throws:
      IllegalArgumentException - If the new password is empty
      SecurityException - If the current password is incorrect
      SQLException - If database operations fail