|
@ -1,6 +1,7 @@ |
|
|
import javax.swing.*; |
|
|
import javax.swing.*; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionListener; |
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
public class SignUpGUI extends JFrame implements ActionListener { |
|
|
public class SignUpGUI extends JFrame implements ActionListener { |
|
@ -64,6 +65,11 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); |
|
|
JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!isUsernameAvailable("user.json", username)) { |
|
|
|
|
|
JOptionPane.showMessageDialog(this, "Username already exists!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
try { |
|
|
try { |
|
|
UUID randomUUID = UUID.randomUUID(); |
|
|
UUID randomUUID = UUID.randomUUID(); |
|
|
CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); |
|
|
CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); |
|
@ -75,6 +81,18 @@ public class SignUpGUI extends JFrame implements ActionListener { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// Function to check if the input username doesn't already exist in the JSON file |
|
|
|
|
|
private boolean isUsernameAvailable(String filename, String username) { |
|
|
|
|
|
List<CreateUser> userList = CreateUser.readUserListFromJsonFile(filename); |
|
|
|
|
|
if (userList != null) { |
|
|
|
|
|
for (CreateUser user : userList) { |
|
|
|
|
|
if (user.getUserName().equals(username)) { |
|
|
|
|
|
return false; // Username already exists |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; // Username is available |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
SwingUtilities.invokeLater(() -> { |
|
|
SwingUtilities.invokeLater(() -> { |
|
|