diff --git a/src/main/java/team/elrant/bubbles/gui/LoginController.java b/src/main/java/team/elrant/bubbles/gui/LoginController.java index 85d45cb..172e9fc 100644 --- a/src/main/java/team/elrant/bubbles/gui/LoginController.java +++ b/src/main/java/team/elrant/bubbles/gui/LoginController.java @@ -3,6 +3,7 @@ import javafx.fxml.FXML; import javafx.scene.AccessibleRole; import javafx.scene.control.*; +import javafx.scene.input.KeyCode; import javafx.stage.Stage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -35,6 +36,8 @@ public class LoginController { private CheckBox seePasswordCheckbox; private @Nullable ConnectedUser connectedUser; + final String contact = "testuser"; + /** * Handles the action when submit button is clicked. @@ -83,12 +86,21 @@ public void initialize() { if (!userFromFile.getUsername().equals("uninit")) { username_field.setText(userFromFile.getUsername()); } - if (!userFromFile.getPassword().equals("uninit")){ - password_field_hidden.setText(userFromFile.getPassword()); + if (!userFromFile.passwordUnInit()){ + userFromFile.setPasswordField(password_field_hidden); + rememberPassword.setSelected(true); } } catch (Exception ignored) { logger.warn("Failed to load user information from file."); } + password_field_hidden.setOnKeyPressed(event ->{ + if(event.getCode() == KeyCode.ENTER) //when Enter is pressed, call sendMessage + onSubmitButtonClick(); + }); + password_field_visible.setOnKeyPressed(event ->{ + if(event.getCode() == KeyCode.ENTER) //when Enter is pressed, call sendMessage + onSubmitButtonClick(); + }); } /** @@ -105,7 +117,7 @@ private void closeLoginWindow() { private void openChatWindow() { try { if (connectedUser != null && connectedUser.isLoggedIn()) { - ChatViewApplication chatViewApplication = new ChatViewApplication(connectedUser, "davica@bubbles.elrant.team"); + ChatViewApplication chatViewApplication = new ChatViewApplication(connectedUser, contact+"@bubbles.elrant.team"); chatViewApplication.start(new Stage()); closeLoginWindow(); } diff --git a/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java b/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java index da9cc5f..c88d9e6 100644 --- a/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java +++ b/src/main/java/team/elrant/bubbles/xmpp/ConnectedUser.java @@ -1,5 +1,7 @@ package team.elrant.bubbles.xmpp; +import javafx.fxml.FXML; +import javafx.scene.control.PasswordField; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -60,10 +62,7 @@ public ConnectedUser(@NotNull String filename) throws IOException, ClassNotFound logger.info("User information loaded from {}", filename); super.username = serializedUser.getUsername(); super.serviceName = serializedUser.getServiceName(); - if (serializedUser.getPassword().equals("uninit")) - this.password = ""; - else - this.password = serializedUser.getPassword(); + this.password = serializedUser.getPassword(); } catch (IOException | ClassNotFoundException e) { logger.error("Error loading user information from file: {}", e.getMessage()); throw e; @@ -207,6 +206,32 @@ public void saveUserToFile(@NotNull String filename, boolean savePassword) { } } + private String getPassword (){ + return password; + } + + + /** + * Sets password field. + * + * @param pwField the fxml password field + */ + public void setPasswordField (PasswordField pwField) { + pwField.setText(this.getPassword()); + } + + /** + * Checks if the password is uninitialized + * + * @return true if the password in uninitialized, false if it isn't + */ + public boolean passwordUnInit() { + if (this.getPassword().equals("uninit")) + return true; + else + return false; + } + /** * Checks if the user is currently logged in.>>>>>>> main *