Skip to content

Commit

Permalink
Feat: Expanded and implemented profile user.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 19, 2026
1 parent f1b0c56 commit b5993b9
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package ntnu.systemutvikling.team6.controller;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.controller.components.BaseController;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarController;
import ntnu.systemutvikling.team6.database.DAO.UserDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.user.*;

public class profileUserSettingsController extends BaseController {
@FXML private NavbarController navbarController;
@FXML private ComboBox<String> languageComboBox;
@FXML private ComboBox<String> themeComboBox;
@FXML private ToggleButton anonymousToggle;
@FXML private Label anonymousLabel;

@FXML private TextField NameField;
@FXML private TextField EmailField;
@FXML private PasswordField PassWordField;
@FXML private TextField ConfirmPasswordField;

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



@Override
protected void authTokenisSet() {
if (!isLoggedin()){
Stage stage = (Stage) anonymousLabel.getScene().getWindow();
LoaderScene.LoadScene("FrontPage", stage,null,null,authToken);
}
navbarController.setAuthToken(authToken);
}
@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");


NameField.setText(user.getUsername());
EmailField.setText(user.getEmail());
PassWordField.setText("Sett new password here");
} else {
languageComboBox.setValue("English");
themeComboBox.setValue("Light mode");
}
}

@FXML
private void handleAnonymousToggle(ActionEvent event) {
boolean on = anonymousToggle.isSelected();
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-max-width: 52; -fx-max-height: 28;"
);
// save to settings
}

@FXML
private void handleNewProfile(ActionEvent event){
String nameText = NameField.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;
}
User newUserCredentials= new User(nameText, emailText, password, Role.NORMAL_USER, new Settings(), new Inbox());

boolean updateSuccess;
DatabaseConnection conn = new DatabaseConnection();
UserDAO userDataObject = new UserDAO(conn);
try {
updateSuccess = userDataObject.updateUserDetails(newUserCredentials);
} catch (Exception e) {
e.printStackTrace();
showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred");
return;
}
if (updateSuccess) {
showAlert(
Alert.AlertType.INFORMATION,
"Settings updated",
"You have successfully changed your settings");
authToken.getCurrentUser().setUsername(nameText);
authToken.getCurrentUser().setPassword(password);
authToken.getCurrentUser().setEmail(emailText);
LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken);
}

}

@FXML
private void handleNewPreferences(ActionEvent event) {
String selectedLanguage = languageComboBox.getValue();
String selectedTheme = themeComboBox.getValue();
boolean isAnonymous = anonymousToggle.isSelected();

Settings updatedSettings = new Settings(
isAnonymous,
selectedLanguage.equals("Norwegian") ? Language.NORWEGIAN : Language.ENGLISH,
selectedTheme.equals("Light mode")
);

DatabaseConnection conn = new DatabaseConnection();
UserDAO userDataObject = new UserDAO(conn);
boolean updateSettingsSuccess;
try {
updateSettingsSuccess = userDataObject.updateUserSettings(authToken.getCurrentUser(), updatedSettings);
} catch (Exception e) {
e.printStackTrace();
showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred");
return;
}
if (updateSettingsSuccess) {
showAlert(
Alert.AlertType.INFORMATION,
"Settings updated",
"You have successfully changed your settings");
authToken.getCurrentUser().setSettings(updatedSettings);
LoaderScene.LoadScene("profile_user_settings", event, null, null, authToken);
}


}

private void handleLogout(ActionEvent event){
authToken.logout();
LoaderScene.LoadScene("FrontPage", event, null, null, authToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?>

<GridPane prefHeight="900.0" prefWidth="1400.0" style="-fx-background-color: #F5F5F5;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.OrganizationSettingsController">
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?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">

<columnConstraints>
<ColumnConstraints minWidth="280.0" prefWidth="300.0" />
Expand Down Expand Up @@ -123,7 +114,7 @@
</children>
</StackPane>

<Label 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 Down Expand Up @@ -204,92 +195,86 @@
<children>
<VBox spacing="6" GridPane.columnIndex="0" GridPane.rowIndex="0">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Full name" />
<TextField prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Username" />
<TextField fx:id="NameField" prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
</children>
</VBox>

<VBox spacing="6" GridPane.columnIndex="1" GridPane.rowIndex="0">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="E-mail" />
<TextField prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
<TextField fx:id="EmailField" prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
</children>
</VBox>

<VBox spacing="6" GridPane.columnIndex="0" GridPane.rowIndex="1">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Donor name" />
<TextField prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Password" />
<PasswordField fx:id="PassWordField" prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
</children>
</VBox>

<VBox spacing="6" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Phone number" />
<TextField prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Confirm Password" />
<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 />
<RowConstraints />
</rowConstraints>
</GridPane>
<HBox prefHeight="48.0" prefWidth="1020.0">
<children>
<Button fx:id="ConfirmChangeSettings" mnemonicParsing="false" onAction="#handleNewProfile" text="Confirm new Profile" />
</children>
</HBox>

<VBox spacing="16" style="-fx-border-color: #379894; -fx-border-width: 2; -fx-padding: 14;">
<children>
<Label style="-fx-font-size: 18px; -fx-text-fill: #666666;" text="Preferences" />
<VBox spacing="16.0" style="-fx-background-color: white; -fx-border-color: #2f8f8b; -fx-border-width: 1.5; -fx-border-radius: 12; -fx-background-radius: 12;" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<padding><Insets bottom="20.0" left="24.0" right="24.0" top="20.0" /></padding>

<HBox spacing="30">
<children>
<VBox spacing="6">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Language" />
<HBox alignment="CENTER_LEFT" prefHeight="36" prefWidth="170" spacing="10" style="-fx-background-color: #F1F3F4; -fx-padding: 0 10 0 10;">
<children>
<Label text="English" />
<Region HBox.hgrow="ALWAYS" />
<Label text="" />
</children>
</HBox>
</children>
</VBox>
<Label style="-fx-font-size: 18;" text="Preferences">
<font><Font name="System Bold" size="18.0" /></font>
</Label>

<VBox spacing="6">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Theme" />
<HBox alignment="CENTER_LEFT" prefHeight="36" prefWidth="170" spacing="10" style="-fx-background-color: #F1F3F4; -fx-padding: 0 10 0 10;">
<children>
<Label text="Light Mode" />
<Region HBox.hgrow="ALWAYS" />
<Label text="" />
</children>
</HBox>
</children>
</VBox>
<HBox alignment="BOTTOM_LEFT" spacing="32.0">

<VBox spacing="6">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Anonymous mode" />
<HBox alignment="CENTER" prefHeight="36" prefWidth="120" spacing="12" style="-fx-background-color: #F1F3F4; -fx-background-radius: 18;">
<children>
<Circle fill="#BFD8D4" radius="10" />
<Label text="Off" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</children>
</VBox>
<!-- Language -->
<VBox spacing="6.0">
<Label style="-fx-text-fill: #888; -fx-font-size: 13;" text="Language" />
<ComboBox fx:id="languageComboBox" prefWidth="160.0" />
</VBox>

<VBox maxWidth="220" spacing="6">
<children>
<Label style="-fx-font-size: 10px; -fx-text-fill: #8A8A8A;" text="Password" />
<TextField prefHeight="36" style="-fx-background-color: #F1F3F4; -fx-background-radius: 2;" />
</children>
<!-- Theme -->
<VBox spacing="6.0">
<Label style="-fx-text-fill: #888; -fx-font-size: 13;" text="Theme" />
<ComboBox fx:id="themeComboBox" prefWidth="160.0" />
</VBox>

<!-- Anonymous mode -->
<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;" />
<Label fx:id="anonymousLabel" style="-fx-text-fill: #888; -fx-font-size: 14;" text="Off" />
</HBox>
</VBox>

</HBox>
</VBox>
<HBox layoutX="50.0" layoutY="294.0" prefHeight="48.0" prefWidth="1020.0">
<children>
<Button fx:id="ConfirmChangeSettings1" mnemonicParsing="false" onAction="#handleNewPreferences" text="Confirm New Preferences" />
</children>
</HBox>
</children>
</VBox>
</GridPane>

0 comments on commit b5993b9

Please sign in to comment.