Skip to content

Commit

Permalink
Feat: Updating user settings work now
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 20, 2026
1 parent 3e298b9 commit 530a61d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void handleLogin(ActionEvent event){
Alert.AlertType.INFORMATION,
"Login Success",
"Login Successful!");
LoaderScene.LoadScene("profile_org_Settings", event, null, null, authToken);
LoaderScene.LoadScene("profile_user_Settings", event, null, null, authToken);
} else {
showAlert(
Alert.AlertType.ERROR,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ntnu.systemutvikling.team6.controller;
package ntnu.systemutvikling.team6.controller.profileUser;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
Expand All @@ -10,7 +9,9 @@
import ntnu.systemutvikling.team6.controller.components.NavbarController;
import ntnu.systemutvikling.team6.database.DAO.UserDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.Readers.UserSelect;
import ntnu.systemutvikling.team6.models.user.*;
import ntnu.systemutvikling.team6.security.PasswordHasher;

public class profileUserSettingsController extends BaseController {
@FXML private NavbarController navbarController;
Expand All @@ -24,6 +25,10 @@ public class profileUserSettingsController extends BaseController {
@FXML private PasswordField PassWordField;
@FXML private TextField ConfirmPasswordField;

@FXML private Label nameLabel;
@FXML private Label shortNameLabel;
@FXML private Label shortNameLabel2;

@FXML private Button ConfirmChangeSettings;
@FXML private Button ConfirmChangeSettings1;

Expand All @@ -36,28 +41,38 @@ protected void authTokenisSet() {
LoaderScene.LoadScene("FrontPage", stage,null,null,authToken);
}
navbarController.setAuthToken(authToken);
populateFields();
}
@FXML
public void initialize() {
languageComboBox.getItems().addAll("English", "Norwegian");
themeComboBox.getItems().addAll("Light mode", "Dark mode");
}

if (authToken != null && authToken.getCurrentUser().getSettings() != null) {
User user = authToken.getCurrentUser();
Settings settings = user.getSettings();
languageComboBox.setValue(settings.getLanguage() == Language.NORWEGIAN ? "Norwegian" : "English");
themeComboBox.setValue(settings.isLightMode() ? "Light mode" : "Dark mode");
anonymousToggle.setSelected(settings.isAnonymous());
anonymousLabel.setText(settings.isAnonymous() ? "On" : "Off");
public void populateFields(){
User user = authToken.getCurrentUser();
Settings settings = user.getSettings();
// Names
nameLabel.setText(user.getUsername());
shortNameLabel.setText(user.getUsername().substring(0,2).toUpperCase().trim());
shortNameLabel2.setText(user.getUsername().substring(0,2).toUpperCase().trim());

// SettingsPage Spesefic:
languageComboBox.setValue(settings.getLanguage() == Language.NORWEGIAN ? "Norwegian" : "English");
themeComboBox.setValue(settings.isLightMode() ? "Light mode" : "Dark mode");
anonymousToggle.setSelected(settings.isAnonymous());

NameField.setText(user.getUsername());
EmailField.setText(user.getEmail());
PassWordField.setText("Sett new password here");
} else {
languageComboBox.setValue("English");
themeComboBox.setValue("Light mode");
}
boolean on = settings.isAnonymous();
anonymousLabel.setText(on ? "On" : "Off");
anonymousToggle.setStyle(
"-fx-background-color: " + (on ? "#2f8f8b" : "#ccc") + ";" +
"-fx-background-radius: 14; -fx-min-width: 32; -fx-min-height: 28;" +
"-fx-max-width: 52; -fx-max-height: 28;"
);


NameField.setText(user.getUsername());
EmailField.setText(user.getEmail());
}

@FXML
Expand All @@ -66,7 +81,7 @@ private void handleAnonymousToggle(ActionEvent event) {
anonymousLabel.setText(on ? "On" : "Off");
anonymousToggle.setStyle(
"-fx-background-color: " + (on ? "#2f8f8b" : "#ccc") + ";" +
"-fx-background-radius: 14; -fx-min-width: 52; -fx-min-height: 28;" +
"-fx-background-radius: 14; -fx-min-width: 32; -fx-min-height: 28;" +
"-fx-max-width: 52; -fx-max-height: 28;"
);
// save to settings
Expand All @@ -93,13 +108,27 @@ private void handleNewProfile(ActionEvent event){
showAlert(Alert.AlertType.ERROR, "Mismatch of password", "Password do not match");
return;
}
User newUserCredentials= new User(nameText, emailText, password, Role.NORMAL_USER, new Settings(), new Inbox());
String hashPassword = new PasswordHasher().getHashPassword(password);
User newUserOnlyCredentials= new User(authToken.getCurrentUser().getId().toString(),nameText, emailText, hashPassword,"NORMAL_USER");

boolean updateSuccess;
DatabaseConnection conn = new DatabaseConnection();
UserDAO userDataObject = new UserDAO(conn);
UserSelect userReaderObject = new UserSelect(conn);
try {
updateSuccess = userDataObject.updateUserDetails(newUserCredentials);
if (!emailText.equals(authToken.getCurrentUser().getEmail())) {
boolean isEmailTaken = userReaderObject.isEmailTaken(emailText);
if (!isEmailTaken) {
updateSuccess = userDataObject.updateUserDetails(newUserOnlyCredentials);
} else {
throw new IllegalArgumentException("Email Alreay taken");
}
} else {
updateSuccess = userDataObject.updateUserDetails(newUserOnlyCredentials);
}
} 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");
Expand All @@ -114,6 +143,8 @@ private void handleNewProfile(ActionEvent event){
authToken.getCurrentUser().setPassword(password);
authToken.getCurrentUser().setEmail(emailText);
LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken);
} else {
System.out.println("Something went wrong when updating Settings");
}

}
Expand Down Expand Up @@ -152,8 +183,32 @@ private void handleNewPreferences(ActionEvent event) {

}

@FXML
private void handleLogout(ActionEvent event){
authToken.logout();
showAlert(Alert.AlertType.INFORMATION, "Logging out", "Logging out...");
LoaderScene.LoadScene("FrontPage", event, null, null, authToken);
}

@FXML
private void switchToFrontPage(ActionEvent event){
LoaderScene.LoadScene("FrontPage", event, null, null, authToken);
}

@FXML
private void switchToInboxPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_inbox", event, null, null, authToken);

}

@FXML
private void switchToHistoryPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_history", event, null, null, authToken);
}

@FXML
private void switchToInterestPage(ActionEvent event){
LoaderScene.LoadScene("profile_user_interests", event, null, null, authToken);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<GridPane prefHeight="67" style="-fx-background-color: #2f8f8b;" HBox.hgrow="ALWAYS" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.components.NavbarController">
<GridPane prefHeight="67" style="-fx-background-color: #2f8f8b;" HBox.hgrow="ALWAYS" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" GridPane.columnSpan="2" fx:controller="ntnu.systemutvikling.team6.controller.components.NavbarController">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="30.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="30.0" prefWidth="100.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>

<GridPane prefHeight="900.0" prefWidth="1400.0" style="-fx-background-color: #F5F5F5;" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.OrganizationSettingsController">
<GridPane prefHeight="900.0" prefWidth="1400.0" style="-fx-background-color: #F5F5F5;" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.profileUser.profileUserSettingsController">

<columnConstraints>
<ColumnConstraints minWidth="280.0" prefWidth="300.0" />
Expand All @@ -23,71 +23,8 @@
<!-- NAVBAR -->
<StackPane style="-fx-background-color: #379894;" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0">
<children>
<GridPane maxWidth="1400.0" prefHeight="52.0" StackPane.alignment="CENTER">
<padding>
<Insets bottom="6.0" left="16.0" right="16.0" top="6.0" />
</padding>

<columnConstraints>
<ColumnConstraints minWidth="40.0" prefWidth="50.0" />
<ColumnConstraints minWidth="140.0" prefWidth="180.0" />
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints minWidth="170.0" prefWidth="190.0" />
</columnConstraints>

<children>
<ImageView fitHeight="34.0" fitWidth="34.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="0">
<image>
<Image url="@../images/Logo.png" />
</image>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</ImageView>

<HBox alignment="CENTER_LEFT" spacing="0.0" GridPane.columnIndex="1">
<children>
<Label style="-fx-text-fill: #FFFFFF;" text="Help">
<font><Font name="System Bold" size="16.0" /></font>
</Label>
<Label prefHeight="62.0" prefWidth="22.0" style="-fx-text-fill: #C8E6C9;" text="Me">
<font><Font name="System Bold" size="16.0" /></font>
</Label>
<Label style="-fx-text-fill: #FFFFFF;" text="Help">
<font><Font name="System Bold" size="16.0" /></font>
</Label>
</children>
</HBox>

<HBox alignment="CENTER" GridPane.columnIndex="2">
<children>
<TextField maxWidth="461.0" prefHeight="28.0" prefWidth="461.0" promptText="Search" style="-fx-background-radius: 14; -fx-border-radius: 14; -fx-font-size: 10px; -fx-padding: 0 0 0 10; -fx-background-color: #FFFFFF;" />
</children>
</HBox>

<HBox alignment="CENTER_RIGHT" spacing="12.0" GridPane.columnIndex="3">
<children>
<StackPane prefHeight="46.0" prefWidth="46.0">
<children>
<Circle fill="WHITE" radius="23.0" />
<Label text="SJ" textFill="#222222">
<font><Font size="14.0" /></font>
</Label>
</children>
</StackPane>

<Button style="-fx-background-color: transparent; -fx-padding: 0;">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
</children>
</HBox>
</children>
<rowConstraints>
<RowConstraints />
</rowConstraints>
</GridPane>
<!-- Pull in the navbar from components with its own controller -->
<fx:include fx:id="navbar" source="components/navbar.fxml" />
</children>
</StackPane>

Expand All @@ -100,8 +37,19 @@
<children>
<HBox alignment="CENTER_LEFT" spacing="8">
<children>
<Label style="-fx-font-size: 20px; -fx-text-fill: #333333;" text="" />
<Label style="-fx-font-size: 14px; -fx-text-fill: #333333;" text="Back" />
<Button onAction="#switchToFrontPage" mnemonicParsing="false"
style="-fx-background-color: transparent;
-fx-border-color: transparent;
-fx-cursor: hand;
-fx-font-size: 14px;
-fx-text-fill: #333333;">
<graphic>
<HBox alignment="CENTER_LEFT" spacing="6.0">
<Label text="" style="-fx-font-size: 20px; -fx-text-fill: #333333;" />
<Label text="Back" style="-fx-font-size: 14px; -fx-text-fill: #333333;" />
</HBox>
</graphic>
</Button>
</children>
</HBox>

Expand All @@ -110,11 +58,11 @@
<StackPane>
<children>
<Circle fill="#F5F5F5" radius="60.0" />
<Label style="-fx-font-size: 22px; -fx-text-fill: #222222;" text="SJ" />
<Label fx:id="shortNameLabel" style="-fx-font-size: 22px; -fx-text-fill: #222222;" text="SJ" />
</children>
</StackPane>

<Label fx:id="NameLabel" text="First name&#10;Last name" textFill="#333333">
<Label fx:id="nameLabel" text="First name&#10;Last name" textFill="#333333">
<font><Font size="18" /></font>
</Label>
</children>
Expand All @@ -127,29 +75,30 @@
<HBox alignment="CENTER_LEFT" spacing="12">
<children>
<Circle fill="#2e7d32" radius="6" />
<Button onAction="#switchToInboxPage" style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Donation History" />
<Button onAction="#switchToHistoryPage" style="-fx-background-color: transparent; -fx-cursor: hand; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Donation History" />

</children>
</HBox>

<HBox alignment="CENTER_LEFT" spacing="12">
<children>
<Circle fill="#ed6c02" radius="6" />
<Button onAction="#switchToEditPage" style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Interests" />
<Button onAction="#switchToInterestPage" style="-fx-background-color: transparent; -fx-cursor: hand; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Interests" />
</children>
</HBox>

<HBox alignment="CENTER_LEFT" spacing="12" style="-fx-padding: 4 0 4 0;">
<children>
<Circle fill="#1f4fd8" radius="6" />
<Button onAction="#switchToSettingsPage" style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Inbox" />
<Button onAction="#switchToInboxPage" style="-fx-background-color: transparent; -fx-cursor: hand; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Inbox" />
</children>
</HBox>
</children>
</VBox>
<HBox alignment="CENTER_LEFT" spacing="12" style="-fx-background-color: #F3F4F6; -fx-background-radius: 24; -fx-padding: 10 14 10 14;">
<children>
<Circle fill="#1f1f1f" radius="6" />
<Button onAction="#switchToPaymentsPage" style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Settings" />
<Button style="-fx-background-color: transparent; -fx-font-size: 20px; -fx-alignment: CENTER_LEFT; -fx-text-fill: #333333;" text="Settings" />
</children>
</HBox>

Expand Down Expand Up @@ -177,7 +126,7 @@
<StackPane>
<children>
<Circle fill="#DCEAEA" radius="32" />
<Label style="-fx-font-size: 22px; -fx-text-fill: #333333;" text="SJ" />
<Label fx:id="shortNameLabel2" style="-fx-font-size: 22px; -fx-text-fill: #333333;" text="SJ" />
</children>
</StackPane>
<Label style="-fx-font-size: 10px; -fx-text-fill: #888888;" text="Change" />
Expand Down Expand Up @@ -220,12 +169,6 @@
<TextField fx:id="ConfirmPasswordField" prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
</children>
</VBox>
<VBox layoutX="10.0" layoutY="10.0" spacing="6">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Full name" />
<TextField fx:id="NameField1" prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
</children>
</VBox>
</children>
<rowConstraints>
<RowConstraints />
Expand Down Expand Up @@ -263,7 +206,7 @@
<VBox spacing="6.0">
<Label style="-fx-text-fill: #888; -fx-font-size: 13;" text="Anonymous mode" />
<HBox alignment="CENTER_LEFT" spacing="10.0">
<ToggleButton fx:id="anonymousToggle" onAction="#handleAnonymousToggle" style="-fx-background-color: #ccc; -fx-background-radius: 14; -fx-min-width: 52; -fx-min-height: 28; -fx-max-width: 52; -fx-max-height: 28;" />
<ToggleButton fx:id="anonymousToggle" onAction="#handleAnonymousToggle" style="-fx-background-color: #ccc; -fx-background-radius: 14; -fx-min-width: 32; -fx-min-height: 28; -fx-max-width: 52; -fx-max-height: 28;" />
<Label fx:id="anonymousLabel" style="-fx-text-fill: #888; -fx-font-size: 14;" text="Off" />
</HBox>
</VBox>
Expand Down

0 comments on commit 530a61d

Please sign in to comment.