diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CreateUserPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CreateUserPageController.java index acbb442..b5a0200 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CreateUserPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CreateUserPageController.java @@ -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; @@ -71,7 +71,7 @@ private void handleCreateAccount(ActionEvent event){ return; } - if (loginSuccess) { + if (registerSuccess) { showAlert( Alert.AlertType.INFORMATION, "Sign up sucsess", @@ -79,20 +79,7 @@ private void handleCreateAccount(ActionEvent event){ 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!"); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java index b3ad1c5..2ae0aee 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java @@ -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. diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java index 0488917..a8d9e0a 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java @@ -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 { @@ -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 diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java index 4a65c8b..85ddea6 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java @@ -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; }