Skip to content

Commit

Permalink
Feat: BaseController gets the HelperMethod showAleart. Now everyone c…
Browse files Browse the repository at this point in the history
…an like show an alert.
  • Loading branch information
AdrianBalunan committed Apr 16, 2026
1 parent d30a4fe commit 950ecdb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ private void handleCreateAccount(ActionEvent event){
return;
}

// Now login
boolean loginSuccess;
// login
boolean registerSuccess;
try {
String username = firstNameText + " " + lastNameText;
loginSuccess = authToken.register(username,emailText, confirmPassword);
registerSuccess = authToken.register(username,emailText, confirmPassword);
} catch (IllegalArgumentException e) {
showAlert(Alert.AlertType.ERROR, "Email already taken", "Email already taken by another user.");
return;
Expand All @@ -71,28 +71,15 @@ private void handleCreateAccount(ActionEvent event){
return;

}
if (loginSuccess) {
if (registerSuccess) {
showAlert(
Alert.AlertType.INFORMATION,
"Sign up sucsess",
"You have registered a new account! Please login with same credentials");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
}
/**
* Show an JavaFx alert dialog with the specified type, title, and message.
*
* @param type
* @param title
* @param message
*/
private void showAlert(Alert.AlertType type, String title, String message) {
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}

@FXML
private void switchToLoginPage(ActionEvent event){
System.out.println("Click!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,7 @@ public void processDonation(Charity charity, User user, double amount) {
donationSender.addDonation(charity, user, amount);
}

/**
* Show an JavaFx alert dialog with the specified type, title, and message.
*
* @param type
* @param title
* @param message
*/
private void showAlert(Alert.AlertType type, String title, String message) {
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}


/**
* This method is used to handle the search action when the user clicks the search button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import ntnu.systemutvikling.team6.service.AuthenticationService;

public abstract class BaseController {
Expand All @@ -22,6 +23,21 @@ protected boolean isLoggedin(){
return authToken != null && authToken.isLoggedin();
}

/**
* Show an JavaFx alert dialog with the specified type, title, and message.
*
* @param type
* @param title
* @param message
*/
protected void showAlert(Alert.AlertType type, String title, String message) {
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}

// Example on the minimum inside of a controller that extends the baseControlle and inserts footer and navbar fxml:
/*
@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ public AuthenticationService(UserSelect userDataReader, UserDAO userDataSender)
* @param password the password of the user attempting to log in
* @return {@code true} if authentication was successful; {@code false} otherwise
*/
public boolean login(String username, String password){
User user = userDataReader.getUserFromDBUsernameAndPassword(username, password);
public boolean login(String email, String password){
User user = userDataReader.getUserFromDBEmailAndPassword(email, password);

if (user != null){
currentUser = user;
System.out.println("User gotten");
return true;
}

Expand Down

0 comments on commit 950ecdb

Please sign in to comment.