java.lang.Object
ai.tutor.cab302exceptionalhandlers.controller.AuthController
ai.tutor.cab302exceptionalhandlers.controller.SignUpController

public class SignUpController extends AuthController
Controls the sign-up screen for creating new user accounts in the AI tutor application.

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:
  • Constructor Details

  • 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 invokes setupConfirmPasswordField() to handle the confirmed password field specific to sign-up.

      Overrides:
      initialize in class AuthController
      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. Calls submitButtonToggle() to enable or disable the submit button accordingly.

      Specified by:
      onFieldChanged in class AuthController
      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 calls onFieldChanged(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, or passwordCEmpty is true, ensuring all fields are filled before submission.

      Specified by:
      submitButtonToggle in class AuthController
    • 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 class AuthController
    • 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 via UserDAO.getUser(String), and creates the user in the database if valid.

      Specified by:
      authenticateUser in class AuthController
      Parameters:
      username - The username for the new user
      password - The password to be hashed and stored
      Returns:
      The newly created User object
      Throws:
      IllegalArgumentException - If the username is already taken
      SQLException - If database operations fail