Browse Source

Added –Universally Unique Identifier for the user signing up

remotes/origin/feature/client/make-input-field-buttons-interactive
Richard Schmidt 11 months ago
parent
commit
eea15e563e
  1. 25
      src/main/java/SignUp.java
  2. 2
      user.json

25
src/main/java/SignUp.java

@ -1,25 +1,36 @@
import com.google.gson.Gson;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;
public class SignUp {
private String id;
private String userName;
private String password;
private String birthday;
// Constructor
public SignUp(String name, String password, String birthday) {
this.userName = name;
public SignUp(String id, String name, String password, String birthday) {
this.id = id;
this.userName = name;
this.password = password;
this.birthday = birthday;
}
// Getters and Setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setName(String userName) {
public void setUserName(String userName) {
this.userName = userName;
}
@ -40,7 +51,7 @@ public class SignUp {
}
// Function to create user with validation
public static SignUp createUser(String userName, String password, String birthday) {
public static SignUp createUser(String id, String userName, String password, String birthday) {
if (userName == null || userName.isEmpty()) {
throw new IllegalArgumentException("Username cannot be empty");
}
@ -49,7 +60,7 @@ public class SignUp {
}
if (password.length() < 6) {
throw new IllegalArgumentException("Password must be at least 6 characters long");
} return new SignUp(userName, password, birthday);
} return new SignUp(id, userName, password, birthday);
}
// Function to save to JSON file, replace with database call later
@ -66,9 +77,11 @@ public class SignUp {
public static void main(String[] args) {
try {
// Example usage
SignUp user = createUser("Test User", "TestPasswort", "01.01.1900");
UUID randomUUID = UUID.randomUUID();
SignUp user = createUser(randomUUID.toString(), "Test User", "TestPasswort", "01.01.1900");
// Example of accessing properties
System.out.println("UserID: " + user.getId());
System.out.println("User Name: " + user.getUserName());
System.out.println("User Password: " + user.getPassword());
System.out.println("User Birthday: " + user.getBirthday());

2
user.json

@ -1 +1 @@
{"userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"}
{"id":"48728bbb-b924-48ce-aac0-3e38d6c7878e","userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"}
Loading…
Cancel
Save