Class SignUpController
Extends AuthController
to inherit common authentication logic and UI handling.
Manages the sign-up form, validates user input (username, password, confirmed password),
and creates new users in the database via UserDAO
.
- See Also:
-
Field Summary
Fields inherited from class ai.tutor.cab302exceptionalhandlers.controller.AuthController
db, passwordEmpty, passwordFeedback, passwordField, submitButton, switchLayout, userDAO, usernameEmpty, usernameFeedback, usernameField
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticateUser
(String username, String password) Authenticates and creates a new user with the provided username and password.void
Initializes the sign-up screen by setting up UI components and event handlers.protected void
onFieldChanged
(javafx.scene.input.KeyEvent e) Handles key events in the sign-up form’s text fields to track input changes.protected void
onSubmit()
Processes the sign-up form submission to create a new user account.protected void
Configures the confirmed password field to respond to key events.protected void
Enables or disables the submit button based on input field states.Methods inherited from class ai.tutor.cab302exceptionalhandlers.controller.AuthController
errorFeedback, loadChat, resetErrorFeedback, setupInputField, setupSubmitButton, setupSwitchLayoutButton, switchLayout
-
Constructor Details
-
SignUpController
- Throws:
RuntimeException
SQLException
-
-
Method Details
-
initialize
public void initialize()Initializes the sign-up screen by setting up UI components and event handlers.Calls the parent class's
AuthController.initialize()
method to configure common authentication UI elements, then invokessetupConfirmPasswordField()
to handle the confirmed password field specific to sign-up.- Overrides:
initialize
in classAuthController
- See Also:
-
onFieldChanged
protected void onFieldChanged(javafx.scene.input.KeyEvent e) Handles key events in the sign-up form’s text fields to track input changes.Updates boolean flags (
usernameEmpty
,passwordEmpty
,passwordCEmpty
) based on whether the username, password, or confirm password fields are empty. CallssubmitButtonToggle()
to enable or disable the submit button accordingly.- Specified by:
onFieldChanged
in classAuthController
- Parameters:
e
- The key event triggered by typing in a text field
-
setupConfirmPasswordField
protected void setupConfirmPasswordField()Configures the confirmed password field to respond to key events.Attaches an event handler to
confirmPasswordField
that callsonFieldChanged(KeyEvent)
when the user types, enabling validation of the confirmed password input. -
submitButtonToggle
protected void submitButtonToggle()Enables or disables the submit button based on input field states.Disables the button if any of
usernameEmpty
,passwordEmpty
, orpasswordCEmpty
is true, ensuring all fields are filled before submission.- Specified by:
submitButtonToggle
in classAuthController
-
onSubmit
protected void onSubmit()Processes the sign-up form submission to create a new user account.Retrieves the username, password, and confirm password from the form fields. Validates that the passwords match, authenticates the user via
authenticateUser(String, String)
, and navigates to the chat screen if successful. Displays error feedback for invalid inputs or mismatches.- Specified by:
onSubmit
in classAuthController
-
authenticateUser
public User authenticateUser(String username, String password) throws IllegalArgumentException, SQLException Authenticates and creates a new user with the provided username and password.Hashes the password using
User.hashPassword(String)
, checks for duplicate usernames viaUserDAO.getUser(String)
, and creates the user in the database if valid.- Specified by:
authenticateUser
in classAuthController
- Parameters:
username
- The username for the new userpassword
- The password to be hashed and stored- Returns:
- The newly created
User
object - Throws:
IllegalArgumentException
- If the username is already takenSQLException
- If database operations fail
-