Skip to content

Commit

Permalink
Feat: Implementing charityUser, new methods for showing its a charity…
Browse files Browse the repository at this point in the history
… user and smaller fixes
  • Loading branch information
AdrianBalunan committed Apr 21, 2026
1 parent ea265eb commit 6cf34de
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void handleCreateAccount(ActionEvent event){
Alert.AlertType.INFORMATION,
"Sign up sucsess",
"You have registered a new account! Please login with same credentials");
LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken);
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ public class NavbarController extends BaseController {
@FXML protected TextField frontSearchField;
@FXML private Button loginButton;
@FXML private Button profileButton;
@FXML private Button toCharityUserButton;

@Override
protected void authTokenisSet() {
boolean loggedIn = super.isLoggedin();
if (loggedIn){
if (authToken.isCharityUser() != null){
toCharityUserButton.setVisible(true);
toCharityUserButton.setManaged(true);
}
loginButton.setVisible(false);
loginButton.setManaged(false);
profileButton.setVisible(true);
Expand All @@ -28,6 +33,8 @@ protected void authTokenisSet() {
loginButton.setManaged(true);
profileButton.setVisible(false);
profileButton.setManaged(false);
toCharityUserButton.setVisible(false);
toCharityUserButton.setManaged(false);
}

}
Expand Down Expand Up @@ -59,4 +66,10 @@ private void switchToLoginPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}

@FXML
private void switchToCharityUserPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void displayDonations(DonationRegistry donationRegistry) {
cardsContainer.getChildren().clear();
List<Donation> donations = donationRegistry.getAllDonations();
if(donations.isEmpty()){
Label empty = new Label("You have no messages");
Label empty = new Label("You have no Donations");
empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;");
cardsContainer.getChildren().add(empty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void populateFields() {
private void displayFavourites(ArrayList<Charity> favourites) {
cardsContainer.getChildren().clear();
if(favourites.isEmpty()){
Label empty = new Label("You have no messages");
Label empty = new Label("You have no favourited Charities");
empty.setStyle("-fx-text-fill: #777777; -fx-font-size: 14;");
cardsContainer.getChildren().add(empty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,23 @@ FOREIGN KEY (`Charities_UUID_charities`)
-- -----------------------------------------------------
-- Table `apbaluna`.`CharityUsers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `apbaluna`.`CharityUsers` (
`Charities_UUID_charities` CHAR(36) NOT NULL,
`User_UUID_User` CHAR(36) NOT NULL,
PRIMARY KEY (`Charities_UUID_charities`, `User_UUID_User`),
INDEX `fk_Charities_has_User_User1_idx` (`User_UUID_User` ASC) VISIBLE,
INDEX `fk_Charities_has_User_Charities1_idx` (`Charities_UUID_charities` ASC) VISIBLE,
CONSTRAINT `fk_Charities_has_User_Charities1`
FOREIGN KEY (`Charities_UUID_charities`)
REFERENCES `apbaluna`.`Charities` (`UUID_charities`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Charities_has_User_User1`
FOREIGN KEY (`User_UUID_User`)
REFERENCES `apbaluna`.`User` (`UUID_User`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `apbaluna`.`CharityUsers` (
`TheCharity` CHAR(36) NOT NULL,
`CharityUserId` CHAR(36) NOT NULL,
PRIMARY KEY (`TheCharity`, `CharityUserId`),
INDEX `fk_Charities_has_User_User1_idx` (`CharityUserId` ASC) VISIBLE,
INDEX `fk_Charities_has_User_Charities1_idx` (`TheCharity` ASC) VISIBLE,
CONSTRAINT `fk_Charities_has_User_Charities1`
FOREIGN KEY (`TheCharity`)
REFERENCES `apbaluna`.`Charities` (`UUID_charities`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Charities_has_User_User1`
FOREIGN KEY (`CharityUserId`)
REFERENCES `apbaluna`.`User` (`UUID_User`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
""";
String charityVanityTable =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.sql.*;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.Feedback;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
import ntnu.systemutvikling.team6.models.registry.UserRegistry;
import ntnu.systemutvikling.team6.models.user.*;
Expand Down Expand Up @@ -59,6 +61,65 @@ public boolean isEmailTaken(String email){
return false;
}

public Charity getUserCharityUser(String uuid){
if (uuid == null || uuid.isBlank()) {
throw new IllegalArgumentException(
"Email cannot be null or blank," + " and must contain '@' and '.'");
}
Charity currentCharity = null;
Connection conn = null;
try {
conn = connection.getMySqlConnection();
String sql_query =
"""
SELECT
c.UUID_charities, c.org_number, c.pre_approved, c.status,
cv.charity_name, cv.charity_link, cv.description, cv.logoURL, cv.key_values, cv.logoBLOB,
cat.category
FROM CharityUsers cu
INNER JOIN Charities c ON c.UUID_charities = cu.TheCharity
INNER JOIN CharityVanity cv ON cv.UUID_charity = c.UUID_charities
LEFT JOIN Charity_Categories cc ON cc.Charities_UUID_charities = c.UUID_charities
LEFT JOIN Categories cat ON cat.category_id = cc.Categories_category_id
WHERE CharityUserId = ?;
""";
PreparedStatement stmt = conn.prepareStatement(sql_query);
stmt.setString(1, uuid);
ResultSet rs = stmt.executeQuery();

String lastCharity = null;

while (rs.next()) {
String currentId = rs.getString("UUID_charities");
if (lastCharity == null || !currentId.equals(lastCharity)) {
currentCharity =
new Charity(
rs.getString("UUID_charities"),
rs.getString("org_number"),
rs.getString("charity_name"),
rs.getString("charity_link"),
rs.getString("status"),
rs.getBoolean("pre_approved"),
rs.getString("description"),
rs.getString("logoURL"),
rs.getString("key_values"),
rs.getBytes("logoBLOB"));
lastCharity = currentId;
}

String categoryName = rs.getString("category");
if (categoryName != null & !currentCharity.getCategory().contains(categoryName)) {
currentCharity.getCategory().add(categoryName);
}
}

} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("ERROR: Something went wrong during updating charities table.");
}
return currentCharity;
}


/**
* Retrieves a single {@link User} from the database matching the given username and password.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ntnu.systemutvikling.team6.database.DAO.UserDAO;
import ntnu.systemutvikling.team6.database.Readers.UserSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.user.Inbox;
import ntnu.systemutvikling.team6.models.user.Role;
import ntnu.systemutvikling.team6.models.user.Settings;
Expand All @@ -24,6 +25,8 @@ public class AuthenticationService {
/** The currently authenticated user, or {@code null} if no user is logged in. */
private User currentUser;

private Charity isCharityUser;

/**
* Constructs an {@code AuthenticationService} with the specified data access objects.
*
Expand All @@ -42,7 +45,7 @@ public AuthenticationService(UserSelect userDataReader, UserDAO userDataSender)
* and the method returns {@code true}.
* </p>
*
* @param username the username of the user attempting to log in
* @param email the username of the user attempting to log in
* @param password the password of the user attempting to log in
* @return {@code true} if authentication was successful; {@code false} otherwise
*/
Expand All @@ -51,6 +54,7 @@ public boolean login(String email, String password){

if (user != null){
currentUser = user;
isCharityUser = userDataReader.getUserCharityUser(currentUser.getId().toString());
System.out.println("User gotten");
return true;
}
Expand Down Expand Up @@ -115,4 +119,6 @@ public User getCurrentUser(){
public boolean isLoggedin(){
return currentUser != null;
}

public Charity isCharityUser(){return isCharityUser;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@
<Font name="System Bold" size="20.0" />
</font>
</Label>
<HBox fx:id="authBox" alignment="CENTER_RIGHT" GridPane.columnIndex="2">
<HBox fx:id="authBox" alignment="CENTER_RIGHT" GridPane.columnIndex="2" spacing="10.0">
<padding>
<Insets right="20.0" />
</padding>
<children>
<Button fx:id="toCharityUserButton" visible="false" onAction="#switchToCharityUserPage" prefHeight="34.0" prefWidth="120.0" style="-fx-background-color: #E07400 ; -fx-text-fill: white; -fx-background-radius: 17; -fx-font-weight: bold;" text="To Charity Settings" />
<Button fx:id="loginButton" onAction="#switchToLoginPage" prefHeight="34.0" prefWidth="120.0" style="-fx-background-color: #1F4FD8; -fx-text-fill: white; -fx-background-radius: 17; -fx-font-weight: bold;" text="Login" />
<Button fx:id="profileButton" managed="false" onAction="#switchToProfilePage"
style="
Expand Down

0 comments on commit 6cf34de

Please sign in to comment.