Skip to content

Commit

Permalink
Added remember_password (still not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciaopersone committed Apr 16, 2024
1 parent 665ba82 commit a1b779a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 70 deletions.
9 changes: 4 additions & 5 deletions src/main/java/team/elrant/bubbles/gui/LoginController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package team.elrant.bubbles.gui;

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.control.*;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -29,6 +26,8 @@ public class LoginController {
private Label failedLoginLabel;
@FXML
private Label successfulLoginLabel;
@FXML
private CheckBox rememberPassword;
private @Nullable ConnectedUser connectedUser;


Expand All @@ -41,7 +40,7 @@ protected void onSubmitButtonClick() {
try {
connectedUser = new ConnectedUser(username_field.getText(), password_field.getText(), "bubbles.elrant.team");
connectedUser.initializeConnection();
connectedUser.saveUserToFile("user.dat");
connectedUser.saveUserToFile("user.dat", rememberPassword.isSelected());
} catch (Exception e) {
logger.error("Error during login: {}", e.getMessage());
failedLoginLabel.setVisible(true);
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ public void acceptSubscription(@NotNull BareJid contactJid, @Nullable String nic
*
* @param filename The name of the file to save the user information to.
*/
public void saveUserToFile(@NotNull String filename) {
public void saveUserToFile(@NotNull String filename, boolean savePassword) {
try (@NotNull FileOutputStream fileOut = new FileOutputStream(filename);
@NotNull ObjectOutputStream objectOut = new ObjectOutputStream(fileOut)) {

@NotNull User userWithoutPassword = new User(super.getUsername(), super.getServiceName());
objectOut.writeObject(userWithoutPassword);
if (savePassword)
objectOut.writeObject(this);
else {
@NotNull User userToFile = new User(super.getUsername(), super.getServiceName());
objectOut.writeObject(userToFile);
}

logger.info("User information (excluding password) saved to {}", filename);
} catch (IOException e) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/team/elrant/bubbles/xmpp/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -18,16 +19,19 @@ public class User implements Serializable {

private final @NotNull String username;
private final @NotNull String serviceName;
private final @Nullable String password;

/**
* Constructs a User object with the specified username and service name.
*
* @param username The username of the user.
* @param serviceName The service name of the XMPP server.
*/
public User(@NotNull String username, @NotNull String serviceName) {

public User(@NotNull String username, @NotNull String serviceName, @NotNull String password) {
this.username = username;
this.serviceName = serviceName;
this.password = password;
}

/**
Expand All @@ -37,7 +41,8 @@ public User(@NotNull String username, @NotNull String serviceName) {
* @throws IOException If an I/O error occurs while reading the file.
* @throws ClassNotFoundException If the class of a serialized object cannot be found.
*/
public User(@NotNull String filename) throws IOException, ClassNotFoundException {
public User(@NotNull String filename, @NotNull String password) throws IOException, ClassNotFoundException {
this.password = password;
try (FileInputStream fileIn = new FileInputStream(filename);
ObjectInputStream objectIn = new ObjectInputStream(fileIn)) {
User serializedUser = (User) objectIn.readObject();
Expand Down
29 changes: 0 additions & 29 deletions src/main/resources/team/elrant/bubbles/gui/SideView.fxml

This file was deleted.

53 changes: 25 additions & 28 deletions src/main/resources/team/elrant/bubbles/gui/views/LoginView.fxml
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<Pane xmlns:fx="http://javafx.com/fxml/1" prefHeight="200.0" prefWidth="280.0"
xmlns="http://javafx.com/javafx/17.0.2-ea" fx:controller="team.elrant.bubbles.gui.LoginController">

<Pane prefHeight="200.0" prefWidth="280.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="team.elrant.bubbles.gui.LoginController">
<AnchorPane layoutY="14.0" prefHeight="169.0" prefWidth="280.0">
<AnchorPane fx:id="formPane" layoutX="22.0" layoutY="55.0" prefHeight="79.0" prefWidth="243.0">
<Label alignment="BASELINE_LEFT" layoutY="4.0" text="Username">
<font>
<Font name="Segoe UI Semibold" size="12.0"/>
<Font name="Segoe UI Semibold" size="12.0" />
</font>
</Label>
<TextField fx:id="username_field" layoutX="78.0" layoutY="1.0" prefHeight="22.0" prefWidth="162.0"
promptText="Username">
<TextField fx:id="username_field" layoutX="78.0" layoutY="1.0" prefHeight="22.0" prefWidth="162.0" promptText="Username">
<font>
<Font name="Segoe UI" size="12.0"/>
<Font name="Segoe UI" size="12.0" />
</font>
</TextField>
<Label alignment="BASELINE_LEFT" layoutX="1.0" layoutY="38.0" text="Password">
<font>
<Font name="Segoe UI Semibold" size="12.0"/>
<Font name="Segoe UI Semibold" size="12.0" />
</font>
</Label>
<PasswordField fx:id="password_field" layoutX="78.0" layoutY="35.0" prefHeight="22.0" prefWidth="162.0"
promptText="********">
<PasswordField fx:id="password_field" layoutX="78.0" layoutY="35.0" prefHeight="22.0" prefWidth="162.0" promptText="********">
<font>
<Font name="Segoe UI" size="12.0"/>
<Font name="Segoe UI" size="12.0" />
</font>
</PasswordField>
<CheckBox fx:id="rememberPassword" layoutX="95.0" layoutY="64.0" mnemonicParsing="false" text="Remember password">
<font>
<Font name="Segoe UI Light" size="12.0" />
</font>
</CheckBox>
</AnchorPane>
<Label fx:id="loginLabel" alignment="BASELINE_CENTER" contentDisplay="CENTER" layoutX="-21.0"
maxWidth="-Infinity" minWidth="-Infinity" prefHeight="39.0" prefWidth="304.0" text="Login"
textAlignment="CENTER">
<Label fx:id="loginLabel" alignment="BASELINE_CENTER" contentDisplay="CENTER" layoutX="-21.0" maxWidth="-Infinity" minWidth="-Infinity" prefHeight="39.0" prefWidth="304.0" text="Login" textAlignment="CENTER">
<font>
<Font name="Segoe UI Semibold" size="25.0"/>
<Font name="Segoe UI Semibold" size="25.0" />
</font>
</Label>
<Button fx:id="submitButton" layoutX="208.0" layoutY="147.0" mnemonicParsing="false"
onAction="#onSubmitButtonClick" text="Submit">
<Button fx:id="submitButton" layoutX="208.0" layoutY="147.0" mnemonicParsing="false" onAction="#onSubmitButtonClick" text="Submit">
<font>
<Font name="Segoe UI" size="12.0"/>
<Font name="Segoe UI" size="12.0" />
</font>
</Button>
<opaqueInsets>
<Insets/>
<Insets />
</opaqueInsets>
</AnchorPane>
<Label fx:id="failedLoginLabel" layoutX="36.0" layoutY="154.0" prefHeight="17.0" prefWidth="174.0"
text="Wrong username or password!" textFill="#b50000" visible="false">
<Label fx:id="failedLoginLabel" layoutX="36.0" layoutY="154.0" prefHeight="17.0" prefWidth="174.0" text="Wrong username or password!" textFill="#b50000" visible="false">
<font>
<Font name="Segoe UI Black" size="12.0"/>
<Font name="Segoe UI Black" size="12.0" />
</font>
</Label>
<Label fx:id="successfulLoginLabel" layoutX="115.0" layoutY="154.0" text="Successful login!" textFill="#00bc00"
visible="false">
<Label fx:id="successfulLoginLabel" layoutX="115.0" layoutY="154.0" text="Successful login!" textFill="#00bc00" visible="false">
<font>
<Font name="Segoe UI Black" size="12.0"/>
<Font name="Segoe UI Black" size="12.0" />
</font>
</Label>
<opaqueInsets>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0"/>
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
</opaqueInsets>
</Pane>
27 changes: 24 additions & 3 deletions src/main/resources/team/elrant/bubbles/gui/views/SideView.fxml
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="720.0" prefWidth="320.0"
xmlns="http://javafx.com/javafx/17.0.2-ea" fx:controller="team.elrant.bubbles.gui.SideViewController">

<AnchorPane prefHeight="720.0" prefWidth="320.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="team.elrant.bubbles.gui.SideViewController">
<children>
<MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="320.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</AnchorPane>

0 comments on commit a1b779a

Please sign in to comment.