Class LoginController
Extends AuthController
to inherit common authentication logic and UI handling.
Manages the login form, validates user input (username, password),
and access existing users in the database via UserDAO
.
- See Also:
-
Field Summary
Fields inherited from class ai.tutor.cab302exceptionalhandlers.controller.AuthController
confirmPasswordField, db, passwordEmpty, passwordFeedback, passwordField, submitButton, switchLayout, userDAO, usernameEmpty, usernameFeedback, usernameField
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticateUser
(String username, String password) Authenticates an existing user with the provided username and password.protected void
onFieldChanged
(javafx.scene.input.KeyEvent e) Handles key events in the login 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
Enables or disables the submit button based on input field states.Methods inherited from class ai.tutor.cab302exceptionalhandlers.controller.AuthController
errorFeedback, initialize, loadChat, resetErrorFeedback, setupInputField, setupSubmitButton, setupSwitchLayoutButton, switchLayout
-
Constructor Details
-
LoginController
- Throws:
RuntimeException
SQLException
-
-
Method Details
-
onFieldChanged
protected void onFieldChanged(javafx.scene.input.KeyEvent e) Handles key events in the login form’s text fields to track input changes.Updates boolean flags (
usernameEmpty
andpasswordEmpty
based on whether the username or 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
-
submitButtonToggle
protected void submitButtonToggle()Enables or disables the submit button based on input field states.Disables the button if any of
usernameEmpty
orpasswordEmpty
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, SecurityException, SQLException Authenticates an existing user with the provided username and password.Checks for an existing username, and verifies the password hash
User.verifyPassword(String)
viaUserDAO.getUser(String)
, and creates the user in the database if valid.- Specified by:
authenticateUser
in classAuthController
- Parameters:
username
- The username for the existing userpassword
- The password to be verified against the hashed password- Returns:
- The existing
User
object - Throws:
IllegalArgumentException
- If the username does not existSecurityException
- if the password is incorrect to the hash verificationSQLException
- If database operations fail
-