Class UserSettingsController
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 Summary
ConstructorsConstructorDescriptionUserSettingsController
(SQLiteConnection connection, User authenticatedUser) Constructs a UserSettingsController with a database connection and user. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Initializes the user settings screen’s UI components and event handlers.void
updatePassword
(String currentPassword, String newPassword) Updates the user’s password after verifying the current password.void
updateUsername
(String newUsername) Updates the user’s username if it has changed.
-
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 aUserDAO
instance, and sets thecurrentUser
whose settings will be managed. Throws an exception if the provided user is null.- Parameters:
connection
- The SQLite database connectionauthenticatedUser
- The currently authenticated user- Throws:
IllegalStateException
- If the user is nullRuntimeException
- If unexpected errors occur during setupSQLException
- 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
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 viaUserDAO.updateUser(User)
. SetsusernameChanged
to true if the update occurs.- Parameters:
newUsername
- The new username to set- Throws:
IllegalArgumentException
- If the username is already takenSQLException
- 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 withUser.hashPassword(String)
, and updates the user in the database viaUserDAO.updateUser(User)
. SetspasswordChanged
to true if the update occurs.- Parameters:
currentPassword
- The user’s current password for verificationnewPassword
- The new password to set- Throws:
IllegalArgumentException
- If the new password is emptySecurityException
- If the current password is incorrectSQLException
- If database operations fail
-