diff --git a/src/main/java/team/elrant/bubbles/gui/LoginApplication.java b/src/main/java/team/elrant/bubbles/gui/LoginApplication.java index 26c70d8..608f413 100644 --- a/src/main/java/team/elrant/bubbles/gui/LoginApplication.java +++ b/src/main/java/team/elrant/bubbles/gui/LoginApplication.java @@ -19,8 +19,10 @@ public void start(@org.jetbrains.annotations.NotNull Stage stage) throws IOExcep Scene scene = new Scene(fxmlLoader.load(), 320, 240); stage.setTitle("Login"); stage.setScene(scene); - scene.getStylesheets().add(BootstrapFX.bootstrapFXStylesheet()); + stage.centerOnScreen(); + stage.setResizable(false); stage.show(); + } } diff --git a/src/main/java/team/elrant/bubbles/gui/LoginController.java b/src/main/java/team/elrant/bubbles/gui/LoginController.java index 80d668d..9f2e037 100644 --- a/src/main/java/team/elrant/bubbles/gui/LoginController.java +++ b/src/main/java/team/elrant/bubbles/gui/LoginController.java @@ -2,8 +2,10 @@ import javafx.fxml.FXML; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; +import javafx.scene.layout.AnchorPane; import team.elrant.bubbles.xmpp.ConnectedUser; public class LoginController { @@ -13,6 +15,10 @@ public class LoginController { private PasswordField password_field; @FXML private Button submitButton; // Reference the button + @FXML + private AnchorPane formPane; // Reference the form pane + @FXML + private Label loginLabel; // Reference the login label @FXML protected void onSubmitButtonClick() { @@ -33,10 +39,7 @@ protected void onSubmitButtonClick() { } @FXML - public void initialize() { // Add an initialize method - // Apply BootstrapFX styling - username_field.getStyleClass().add("form-control"); - password_field.getStyleClass().add("form-control"); - submitButton.getStyleClass().addAll("btn", "btn-primary"); + public void initialize() { + // Styling goes here } } diff --git a/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java b/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java index 922cfd0..c01a41a 100644 --- a/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java +++ b/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java @@ -14,18 +14,27 @@ import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.impl.JidCreate; -import java.io.IOException; +import java.io.*; +/** + * The ConnectedUser class extends the User class. + * It describes how the app's current user should connect, behave, send messages, etc. + */ public class ConnectedUser extends User { private final String password; private Roster roster; - private AbstractXMPPConnection connection = null; + private AbstractXMPPConnection connection = null; // When accessing this property, make sure it's not null + // (or just run InitializeConnection first) public ConnectedUser(String username, String password, String serviceName) { super(username, serviceName); this.password = password; } + /** + * The InitializeConnection method takes no parameters and connects to the server. + * After connecting, it sends a message to the test user. + */ public void initializeConnection() { try { // 1. Create the connection configuration @@ -45,10 +54,10 @@ public void initializeConnection() { // 4. Get the roster roster = Roster.getInstanceFor(connection); - roster.reloadAndWait(); // Ensure roster is up-to-date + roster.reloadAndWait(); // Initialize it - if (!super.getUsername().equals("dummy")) { - // 5. Add or remove contacts as needed + if (!super.getUsername().equals("dummy") && !super.getServiceName().equals("elrant.team")) { + // 5. Add the test user to the roster as needed BareJid dummyJid = JidCreate.bareFrom("dummy@elrant.team"); if (roster.getEntry(dummyJid) == null) { addContact(dummyJid.toString(), "Dummy"); @@ -113,4 +122,47 @@ public Roster getRoster() { public boolean isLoggedIn() { return connection.isAuthenticated(); } + + /** + * Saves the user information (excluding password) to a file. + * @param filename The name of the file to save the user information to. + */ + public void saveUserToFile(String filename) { + try (FileOutputStream fileOut = new FileOutputStream(filename); + ObjectOutputStream objectOut = new ObjectOutputStream(fileOut)) { + + // Create a temporary user object without the password + User userWithoutPassword = new User(super.getUsername(), super.getServiceName()); + + // Write the user object (without password) to the file + objectOut.writeObject(userWithoutPassword); + + System.out.println("User information (excluding password) saved to " + filename); + } catch (IOException e) { + System.err.println("Error saving user information to file: " + e); + } + } + + /** + * Loads the user information from a file and initializes a ConnectedUser object. + * @param filename The name of the file containing the serialized user information. + * @return A ConnectedUser object initialized with the loaded user information. + */ + public static ConnectedUser loadUserFromFile(String filename) { + ConnectedUser connectedUser = null; + try (FileInputStream fileIn = new FileInputStream(filename); + ObjectInputStream objectIn = new ObjectInputStream(fileIn)) { + + // Read the serialized user object from the file + User user = (User) objectIn.readObject(); + + // Initialize a new ConnectedUser object with the loaded user information + connectedUser = new ConnectedUser(user.getUsername(), "password", user.getServiceName()); + + System.out.println("User information loaded from " + filename); + } catch (IOException | ClassNotFoundException e) { + System.err.println("Error loading user information from file: " + e); + } + return connectedUser; + } } diff --git a/src/main/resources/team/elrant/bubbles/gui/LoginView.fxml b/src/main/resources/team/elrant/bubbles/gui/LoginView.fxml index fb85151..5d6f391 100644 --- a/src/main/resources/team/elrant/bubbles/gui/LoginView.fxml +++ b/src/main/resources/team/elrant/bubbles/gui/LoginView.fxml @@ -1,29 +1,32 @@ - - - - - - - - -