Skip to content

Commit

Permalink
Add documentation so deepsource doesnt kill me
Browse files Browse the repository at this point in the history
  • Loading branch information
code-irisnk committed Mar 15, 2024
1 parent d890ba0 commit 380aa43
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/main/java/team/elrant/bubbles/gui/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import team.elrant.bubbles.xmpp.ConnectedUser;
import team.elrant.bubbles.xmpp.User;

import java.io.IOException;

/**
* The LoginController class controls the login functionality in the GUI.
* It handles user authentication and navigation to the main application.
Expand All @@ -24,9 +22,9 @@ public class LoginController {
private static final Logger logger = LogManager.getLogger(LoginController.class);

@FXML
private TextField usernameField;
private TextField username_field;
@FXML
private PasswordField passwordField;
private PasswordField password_field;
@FXML
private Button submitButton;
@FXML
Expand All @@ -37,30 +35,24 @@ public class LoginController {
private Label failedLoginLabel;
@FXML
private Label successfulLoginLabel;

private ConnectedUser connectedUser = null;
private @Nullable ConnectedUser connectedUser = null;

/**
* Handles the action when the submit button is clicked.
* It attempts to log in the user using the provided credentials and navigates to the main application upon successful login.
*/
@FXML
protected void onSubmitButtonClick() {
String username = usernameField.getText();
String password = passwordField.getText();

try {
connectedUser = new ConnectedUser(username, password, "elrant.team");
connectedUser = new ConnectedUser(username_field.getText(), password_field.getText(), "elrant.team");
connectedUser.initializeConnection();
connectedUser.saveUserToFile("user.dat");
successfulLoginLabel.setVisible(true);
} catch (IOException | InterruptedException | SmackException | XMPPException e) {
} catch (Exception e) {
logger.error("Error during login: " + e.getMessage());
failedLoginLabel.setVisible(true);
}

if (connectedUser != null && connectedUser.isLoggedIn()) {
closeLoginWindow();
openChatWindow();
}
}
Expand All @@ -73,20 +65,25 @@ protected void onSubmitButtonClick() {
public void initialize() {
try {
User userFromFile = new User("user.dat");
String storedUsername = userFromFile.getUsername();
if (storedUsername != null && !storedUsername.isEmpty()) {
usernameField.setText(storedUsername);
if (userFromFile.getUsername() != null && !userFromFile.getUsername().isEmpty()) {
username_field.setText(userFromFile.getUsername());
}
} catch (Exception e) {
logger.error("Error loading user information from file: " + e.getMessage());
} catch (Exception ignored) {
logger.warn("Failed to load user information from file.");
}
}

/**
* Closes the login window.
*/
private void closeLoginWindow() {
Stage stage = (Stage) submitButton.getScene().getWindow();
stage.close();
}

/**
* Opens the chat window.
*/
private void openChatWindow() {
try {
ChatViewApplication chatViewApplication = new ChatViewApplication(connectedUser, "lucadg@elrant.team");
Expand Down

0 comments on commit 380aa43

Please sign in to comment.