Skip to content

Commit

Permalink
Merge pull request #77 from cathrkri/56-user-implemention-and-token
Browse files Browse the repository at this point in the history
56 user implemention and token.
  • Loading branch information
apbaluna authored Apr 21, 2026
2 parents 7434cb8 + 4da7e5d commit ef3b1bf
Show file tree
Hide file tree
Showing 71 changed files with 5,232 additions and 6,043 deletions.
Binary file modified docs/SqlDatabase/ER-DiagramFile.mwb
Binary file not shown.
Binary file modified docs/SqlDatabase/ER-DiagramFile.mwb.bak
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@
import java.util.Objects;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.database.DAO.UserDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.DatabaseSetup;
import ntnu.systemutvikling.team6.database.Readers.UserSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.scraper.FullCharityScrape;
import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import ntnu.systemutvikling.team6.service.AuthenticationService;

public class HmHApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
DatabaseConnection conn = new DatabaseConnection();
AuthenticationService authToken = new AuthenticationService(new UserSelect(conn), new UserDAO(conn));

FXMLLoader fxmlLoader =
new FXMLLoader(HmHApplication.class.getResource("/fxml/frontPage.fxml"));
Scene scene = new Scene(fxmlLoader.load());


BaseController controller = fxmlLoader.getController();
controller.setAuthToken(authToken);

Image icon =
new Image(
Objects.requireNonNull(HmHApplication.class.getResource("/images/Logo.png"))
Expand Down Expand Up @@ -72,6 +86,8 @@ public void init() {
e.printStackTrace();
}
System.out.println("-- \n Init complete \n --");


}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ntnu.systemutvikling.team6.controller;

import javafx.fxml.FXML;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.FooterController;
import ntnu.systemutvikling.team6.controller.components.NavbarController;

public class AboutPageController extends BaseController {
@FXML private NavbarController navbarController;
@FXML private FooterController footerController;

@Override
protected void authTokenisSet() {
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import javafx.scene.Parent;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarFooterController;
import ntnu.systemutvikling.team6.controller.components.OrganizationCardController;
import ntnu.systemutvikling.team6.controller.components.*;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
import ntnu.systemutvikling.team6.models.Charity;
Expand All @@ -26,15 +23,22 @@
* on the featured charity to see more details about it. The user can also switch to the charity
* page or donation page for the selected charity.
*/
public class AvailableOrganizationController extends BaseController
implements NavbarFooterController {
public class AvailableOrganizationController extends BaseController {

@FXML private TextField searchField;
@FXML private FlowPane cardsContainer;
@FXML private NavbarController navbarController;
@FXML private FooterController footerController;

private Charity charity;
private List<Charity> allCharities;

@Override
protected void authTokenisSet(){
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}

/**
* This method is used to initialize the available organization page. It retrieves all charities
* from the database and sets up a listener on the search field to filter the charities based on
Expand Down Expand Up @@ -93,8 +97,7 @@ private void displayCharities(List<Charity> charities) {

for (Charity charity : charities) {
try {
FXMLLoader loader =
new FXMLLoader(getClass().getResource("/fxml/components/organizationCard.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/organizationCard.fxml"));
Parent card = loader.load();

OrganizationCardController cardController = loader.getController();
Expand All @@ -121,13 +124,14 @@ public void setInitialSearch(String query) {
searchField.setText(query);
}


/**
* This method is used to switch to the charity page for the selected charity.
*
* @param event action event from button click
*/
public void switchToCharityPage(ActionEvent event) {
LoaderScene.LoadScene("CharityPage", event, charity, null);
LoaderScene.LoadScene("CharityPage", event, charity, null, authToken);
}

/**
Expand All @@ -137,6 +141,6 @@ public void switchToCharityPage(ActionEvent event) {
*/
@FXML
public void switchToDonationPage(ActionEvent event) {
LoaderScene.LoadScene("DonationPage", event, charity, null);
LoaderScene.LoadScene("DonationPage", event, charity, null, authToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ntnu.systemutvikling.team6.controller;

import javafx.event.ActionEvent;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
Expand All @@ -15,14 +15,17 @@
import javafx.scene.layout.VBox;
import javafx.scene.shape.Arc;
import javafx.scene.shape.Rectangle;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.FooterController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarController;
import ntnu.systemutvikling.team6.models.Charity;

/**
* This controller represents the charity page, where the user can read about the charity and choose
* to donate to it. It also has a button to return to the front page.
*/
public class CharityPageController {
public class CharityPageController extends BaseController {
@FXML private TextField charitySearchField;

@FXML private Label CharityDescription;
Expand All @@ -47,9 +50,19 @@ public class CharityPageController {

@FXML private VBox categoriesContainer;

@FXML private NavbarController navbarController;
@FXML private FooterController footerController;

@FXML
public void initialize() {}

@Override
protected void authTokenisSet(){
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}


private Charity charity;

/**
Expand All @@ -69,6 +82,7 @@ public void setCharity(Charity charity) {
CharityDescription.setText(charity.getDescription());
CharityName.setText(charity.getName());


if (this.charity.getLogoBlob() != null) {
ByteArrayInputStream logoByteStream = new ByteArrayInputStream(this.charity.getLogoBlob());
Image CharityLogoImage = new Image(logoByteStream);
Expand Down Expand Up @@ -112,13 +126,13 @@ public void setCharity(Charity charity) {
@FXML
public void switchToDonationPage(ActionEvent event) {
System.out.println("Click");
LoaderScene.LoadScene("donationPage", event, charity, null);
LoaderScene.LoadScene("donationPage", event, charity, null, authToken);
}

@FXML
public void switchToFrontPage(ActionEvent event) {
System.out.println("Click");
LoaderScene.LoadScene("FrontPage", event, charity, null);
LoaderScene.LoadScene("FrontPage", event, charity, null, authToken);
}

/**
Expand All @@ -127,14 +141,9 @@ public void switchToFrontPage(ActionEvent event) {
* @param event is the event that triggered the search.
*/
@FXML
public void handleSearch(ActionEvent event) {
String query = charitySearchField.getText().trim();

if (query.isEmpty()) {
return;
}
private void switchToFeedbackPage(ActionEvent event){
LoaderScene.LoadScene("giveFeedback", event, charity, null, authToken);

LoaderScene.LoadScene("availableOrganization", event, null, query);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ntnu.systemutvikling.team6.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.FooterController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarController;



public class CreateUserPageController extends BaseController {
@FXML
private NavbarController navbarController;
@FXML
private FooterController footerController;

@FXML private TextField firstNameField;
@FXML private TextField emailField;
@FXML private PasswordField passwordField;
@FXML private PasswordField confirmPasswordField;


@Override
protected void authTokenisSet() {
if (isLoggedin()){
LoaderScene.LoadScene("frontPage", new ActionEvent(), null, null, authToken);
}
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}

@FXML
private void handleCreateAccount(ActionEvent event){
String nameText = firstNameField.getText();
String emailText = emailField.getText();
String password = passwordField.getText();
String confirmPassword = confirmPasswordField.getText();

if (nameText.isBlank() || emailText.isBlank() || password.isBlank() || confirmPassword.isBlank()) {
showAlert(Alert.AlertType.ERROR, "Empty input", "Please fill out all fields");
return;
}

if (emailText == null || emailText.isBlank() || !emailText.contains("@") || !emailText.contains(".")) {
showAlert(Alert.AlertType.ERROR, "Invalid Email", "Please enter a valid email");
return;
}

if (!password.equals(confirmPassword)) {
showAlert(Alert.AlertType.ERROR, "Mismatch of password", "Password do not match");
return;
}

// login
boolean registerSuccess;
try {
registerSuccess = authToken.register(nameText,emailText, confirmPassword);
} catch (IllegalArgumentException e) {
showAlert(Alert.AlertType.ERROR, "Email already taken", "Email already taken by another user.");
return;
} catch (Exception e) {
e.printStackTrace();
showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred");
return;

}
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);
}
}

@FXML
private void switchToLoginPage(ActionEvent event){
System.out.println("Click!");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
}
Loading

0 comments on commit ef3b1bf

Please sign in to comment.