diff --git a/src/main/java/org/to/telegramfinalproject/Client/ActionHandler.java b/src/main/java/org/to/telegramfinalproject/Client/ActionHandler.java index 1ec86bd..644a1c2 100644 --- a/src/main/java/org/to/telegramfinalproject/Client/ActionHandler.java +++ b/src/main/java/org/to/telegramfinalproject/Client/ActionHandler.java @@ -500,9 +500,6 @@ public class ActionHandler { } } - - - break; @@ -895,13 +892,6 @@ public class ActionHandler { return true; } - - - - - - - private void transferOwnershipAndLeave(UUID groupId) { JSONObject req = new JSONObject(); req.put("action", "view_group_admins"); @@ -1088,9 +1078,6 @@ public class ActionHandler { System.out.println(promoteRes.getString("message")); } - - - private void addAdminToGroup(UUID groupId) { JSONObject req = new JSONObject(); req.put("action", "view_group_members"); @@ -1152,7 +1139,6 @@ public class ActionHandler { System.out.println(promoteRes.getString("message")); } - private void viewGroupMembers(UUID groupId) { JSONObject req = new JSONObject(); req.put("action", "view_group_members"); @@ -1177,8 +1163,6 @@ public class ActionHandler { } } - - private void removeAdminFromGroup(UUID groupId) { System.out.print("Enter user_id to remove from admin: "); String userId = scanner.nextLine().trim(); @@ -1910,10 +1894,6 @@ public class ActionHandler { } - - - - private JSONObject sendWithResponse(JSONObject request) { try { if (!request.has("action") || request.isNull("action")) { @@ -1940,6 +1920,4 @@ public class ActionHandler { return null; } } - - } diff --git a/src/main/java/org/to/telegramfinalproject/Models/User.java b/src/main/java/org/to/telegramfinalproject/Models/User.java index 9e5781e..73ac635 100644 --- a/src/main/java/org/to/telegramfinalproject/Models/User.java +++ b/src/main/java/org/to/telegramfinalproject/Models/User.java @@ -118,8 +118,4 @@ public class User { public List getChatList(){return this.chatList;} - - - -} - +} \ No newline at end of file diff --git a/src/main/java/org/to/telegramfinalproject/UI/LoginController.java b/src/main/java/org/to/telegramfinalproject/UI/LoginController.java index c26a534..4c35011 100644 --- a/src/main/java/org/to/telegramfinalproject/UI/LoginController.java +++ b/src/main/java/org/to/telegramfinalproject/UI/LoginController.java @@ -35,7 +35,7 @@ public class LoginController { visiblePasswordField.textProperty().bindBidirectional(passwordField.textProperty()); try { - connection = new ClientConnection("localhost", 12345); + connection = new ClientConnection("localhost", 8000); } catch (Exception e) { System.out.println("Could not connect to server: " + e.getMessage()); } diff --git a/src/main/java/org/to/telegramfinalproject/UI/LoginForm.java b/src/main/java/org/to/telegramfinalproject/UI/LoginForm.java deleted file mode 100644 index 79ae18e..0000000 --- a/src/main/java/org/to/telegramfinalproject/UI/LoginForm.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.to.telegramfinalproject.UI; - - -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.Alert; -import javafx.scene.control.Button; -import javafx.scene.control.PasswordField; -import javafx.scene.control.TextField; -import javafx.stage.Stage; -import org.json.JSONObject; -import org.to.telegramfinalproject.Client.ClientConnection; -import org.to.telegramfinalproject.Database.userDatabase; -import org.to.telegramfinalproject.Models.User; -import org.to.telegramfinalproject.Security.PasswordHashing; - -import java.io.IOException; - -public class LoginForm { - - @FXML - private Button loginButton; - @FXML - private Button backButton; - @FXML private TextField usernameField; - @FXML private PasswordField passwordField; - - private ClientConnection connection; - - @FXML - public void initialize() { - - try { - connection = new ClientConnection("localhost", 12345); - } catch (Exception e) { - System.out.println("Could not connect to server: " + e.getMessage()); - } - - loginButton.setOnAction(e -> { - String username = usernameField.getText(); - String password = passwordField.getText(); - - JSONObject request = new JSONObject(); - request.put("action", "login"); - request.put("user_id", JSONObject.NULL); - request.put("username", username); - request.put("password", password); - request.put("profile_name", JSONObject.NULL); - if (connection!=null) { - connection.send(request.toString()); - } - userDatabase userDb = new userDatabase(); - User user = userDb.findByUsername(username); - - if(!userDb.existsByUsername(username)){ - Alert alert = new Alert(Alert.AlertType.ERROR, "Invalid username"); - alert.show(); - } - else if(!PasswordHashing.verify(password,user.getPassword())){ - Alert alert = new Alert(Alert.AlertType.ERROR, "Invalid password"); - alert.show(); - } - else if(!PasswordHashing.verify(password,user.getPassword()) && !userDb.existsByUsername(username)){ - Alert alert = new Alert(Alert.AlertType.ERROR, "Invalid password and username"); - alert.show(); - } - else{ - try { - String responseStr = connection.receive(); - JSONObject response = new JSONObject(responseStr); - System.out.println("Status: " + response.getString("status")); - System.out.println("Message: " + response.getString("message")); - Alert alert = new Alert(Alert.AlertType.INFORMATION, " Message: " + response.getString("message")); - alert.show(); - } catch (Exception ex) { - Alert alert = new Alert(Alert.AlertType.ERROR, "Error receiving response: " + ex.getMessage()); - alert.show(); - } - } - }); - - backButton.setOnAction(e -> { - switchScene("login_view.fxml"); - }); - - - } - - private void switchScene(String fxmlFile) { - try { - - FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/to/telegramfinalproject/" + fxmlFile)); - Parent root = loader.load(); - - - Stage stage = (Stage) backButton.getScene().getWindow(); - stage.setScene(new Scene(root)); - stage.show(); - - } catch (IOException e) { - e.printStackTrace(); - } - } -} - diff --git a/src/main/java/org/to/telegramfinalproject/UI/RegisterController.java b/src/main/java/org/to/telegramfinalproject/UI/RegisterController.java index 22bda84..a8f29bb 100644 --- a/src/main/java/org/to/telegramfinalproject/UI/RegisterController.java +++ b/src/main/java/org/to/telegramfinalproject/UI/RegisterController.java @@ -43,7 +43,7 @@ public class RegisterController { visibleConfirmPasswordField.textProperty().bindBidirectional(confirmPasswordField.textProperty()); try { - connection = new ClientConnection("localhost", 12345); + connection = new ClientConnection("localhost", 8000); } catch (Exception e) { System.out.println("Could not connect to server: " + e.getMessage()); } @@ -81,7 +81,7 @@ public class RegisterController { String passwordRegex = "\\b(?=[^\\s]*[A-Z])(?=[^\\s]*[a-z])(?=[^\\s]*\\d)(?=[^\\s]*[!@#$%^&*])[^\\s]{8,}\\b"; // 1. Empty fields - if (username.isEmpty() || profileName.isEmpty() || password.isEmpty() || confirmPass.isEmpty()) { + if (userID.isEmpty() || username.isEmpty() || profileName.isEmpty() || password.isEmpty() || confirmPass.isEmpty()) { showError("Please fill in all required fields."); return; } @@ -92,8 +92,8 @@ public class RegisterController { return; } - // 3. User ID exists (if entered) - if (!userID.isEmpty() && userDb.existsByUserId(userID)) { + // 3. User ID exists + if (userDb.existsByUserId(userID)) { showError("This user ID is already taken."); return; } @@ -114,12 +114,13 @@ public class RegisterController { try { JSONObject request = new JSONObject(); request.put("action", "register"); - request.put("user_id", userID.isEmpty() ? JSONObject.NULL : userID); + request.put("user_id", userID); request.put("username", username); request.put("password", password); request.put("profile_name", profileName); connection.send(request.toString()); + // Simulate successful registration (since main.fxml isn’t ready) Alert alert = new Alert(Alert.AlertType.INFORMATION, "Registration successful!"); alert.show(); @@ -137,7 +138,7 @@ public class RegisterController { try { FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/to/telegramfinalproject/" + fxmlFile)); Parent root = loader.load(); - Stage stage = (Stage) usernameField.getScene().getWindow(); // Or any node from your current scene + Stage stage = (Stage) usernameField.getScene().getWindow(); stage.setScene(new Scene(root, 500, 700)); stage.show(); } catch (IOException e) { diff --git a/src/main/java/org/to/telegramfinalproject/UI/RegisterForm.java b/src/main/java/org/to/telegramfinalproject/UI/RegisterForm.java deleted file mode 100644 index 4ef6d2e..0000000 --- a/src/main/java/org/to/telegramfinalproject/UI/RegisterForm.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.to.telegramfinalproject.UI; - - -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.Alert; -import javafx.scene.control.Button; -import javafx.scene.control.PasswordField; -import javafx.scene.control.TextField; -import javafx.stage.Stage; -import org.json.JSONObject; -import org.to.telegramfinalproject.Client.ClientConnection; -import org.to.telegramfinalproject.Database.userDatabase; - -import java.io.IOException; - -public class RegisterForm { - @FXML - private Button submitButton; - @FXML - private Button backButton; - @FXML private TextField userIdField; - @FXML private TextField usernameField; - @FXML private TextField profileNameField; - @FXML private PasswordField passwordField; - @FXML private PasswordField confirmPasswordField; - - - - private ClientConnection connection; - - @FXML - public void initialize() { - - try { - connection = new ClientConnection("localhost", 12345); - } catch (Exception e) { - System.out.println("Could not connect to server: " + e.getMessage()); - } - - submitButton.setOnAction(e -> { - String userID = userIdField.getText(); - String username = usernameField.getText(); - String profile_name = profileNameField.getText(); - String password = passwordField.getText(); - String confirmPass =confirmPasswordField.getText(); - JSONObject request = new JSONObject(); - String passwordRegex = "\\b(?=[^\\s]*[A-Z])(?=[^\\s]*[a-z])(?=[^\\s]*\\d)(?=[^\\s]*[!@#$%^&*])[^\\s]{8,}\\b"; - - userDatabase userDb = new userDatabase(); - if(password.equals(confirmPass) && password.matches(passwordRegex) && !userDb.existsByUserId(userID)&& !userDb.existsByUsername(username)){ - try { - request.put("action", "register"); - request.put("user_id", userID); - request.put("username", username); - request.put("password", password); - request.put("profile_name", profile_name); - connection.send(request.toString()); - Alert alert = new Alert(Alert.AlertType.INFORMATION, "Registration is successful"); - alert.show(); - - } catch (Exception ex) { - Alert alert = new Alert(Alert.AlertType.ERROR, "Error receiving response: " + ex.getMessage()); - alert.show(); - } - - } - else if(!password.equals(confirmPass) && password.matches(passwordRegex)) { - Alert alert = new Alert(Alert.AlertType.ERROR, "Password doesn't match"); - alert.show(); - } - else if(userDb.existsByUserId(userID)) - { - Alert alert = new Alert(Alert.AlertType.ERROR, "User ID is already exist"); - alert.show(); - } - else if(userDb.existsByUsername(username)){ - Alert alert = new Alert(Alert.AlertType.ERROR, "Username is already exist"); - alert.show(); - } - else { - Alert alert = new Alert(Alert.AlertType.ERROR, "Password isn't Strong enough"); - alert.show(); - } - }); - - backButton.setOnAction(e -> { - switchScene("login_view.fxml"); - }); - } - - private void switchScene(String fxmlFile) { - try { - - FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/to/telegramfinalproject/" + fxmlFile)); - Parent root = loader.load(); - - - Stage stage = (Stage) backButton.getScene().getWindow(); - stage.setScene(new Scene(root)); - stage.show(); - - } catch (IOException e) { - e.printStackTrace(); - } - } -} - diff --git a/src/main/java/org/to/telegramfinalproject/UI/login_view.java b/src/main/java/org/to/telegramfinalproject/UI/login_view.java deleted file mode 100644 index c89ef01..0000000 --- a/src/main/java/org/to/telegramfinalproject/UI/login_view.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.to.telegramfinalproject.UI; - -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.stage.Stage; - -import java.io.IOException; - -public class login_view { - - @FXML - private Button loginButton; - - @FXML - private Button registerButton; - - @FXML - public void initialize() { - - loginButton.setOnAction(e -> { - switchScene("LoginForm.fxml"); - }); - - registerButton.setOnAction(e -> { - switchScene("register_view.fxml"); - }); - } - - private void switchScene(String fxmlFile) { - try { - - FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/to/telegramfinalproject/" + fxmlFile)); - Parent root = loader.load(); - - - Stage stage = (Stage) loginButton.getScene().getWindow(); - stage.setScene(new Scene(root)); - stage.show(); - - } catch (IOException e) { - e.printStackTrace(); - } - } -} - diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 188772f..aef3e21 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS users( - user_id VARCHAR(70) UNIQUE, + user_id VARCHAR(70) UNIQUE NOT NULL, internal_uuid UUID PRIMARY KEY, username VARCHAR(50) UNIQUE NOT NULL, password TEXT NOT NULL, diff --git a/src/main/resources/org/to/telegramfinalproject/Contact_Cell.fxml b/src/main/resources/org/to/telegramfinalproject/Contact_Cell.fxml deleted file mode 100644 index 7dd1d98..0000000 --- a/src/main/resources/org/to/telegramfinalproject/Contact_Cell.fxml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/org/to/telegramfinalproject/LoginForm.fxml b/src/main/resources/org/to/telegramfinalproject/LoginForm.fxml deleted file mode 100644 index 3c3430e..0000000 --- a/src/main/resources/org/to/telegramfinalproject/LoginForm.fxml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/org/to/telegramfinalproject/MainPage.fxml b/src/main/resources/org/to/telegramfinalproject/MainPage.fxml deleted file mode 100644 index a637fda..0000000 --- a/src/main/resources/org/to/telegramfinalproject/MainPage.fxml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/org/to/telegramfinalproject/register_view.fxml b/src/main/resources/org/to/telegramfinalproject/register_view.fxml index 3e67a29..5ec8499 100644 --- a/src/main/resources/org/to/telegramfinalproject/register_view.fxml +++ b/src/main/resources/org/to/telegramfinalproject/register_view.fxml @@ -16,7 +16,7 @@ style="-fx-font-size: 24px; -fx-font-weight: bold;" />