|
|
@ -111,11 +111,31 @@ class CreateUser { |
|
|
|
return userList; |
|
|
|
} |
|
|
|
|
|
|
|
// Function to update stayLoggedIn variable in the JSON file |
|
|
|
public static void updateStayLoggedIn(String filename, String username, boolean stayLoggedIn) { |
|
|
|
List<CreateUser> userList = readUserListFromJsonFile(filename); |
|
|
|
|
|
|
|
for (CreateUser user : userList) { |
|
|
|
if (user.getUserName().equals(username)) { |
|
|
|
user.setStayLoggedIn(stayLoggedIn); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
try (FileWriter fileWriter = new FileWriter(filename)) { |
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
|
|
|
gson.toJson(userList, fileWriter); |
|
|
|
System.out.println("StayLoggedIn updated in " + filename); |
|
|
|
} catch (IOException e) { |
|
|
|
System.out.println("Error occurred while updating StayLoggedIn in JSON file: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
try { |
|
|
|
// Example usage |
|
|
|
UUID randomUUID = UUID.randomUUID(); |
|
|
|
CreateUser user = createUser(randomUUID.toString(), "Another Test User", "TestPasswort123", "01.01.2000"); |
|
|
|
CreateUser user = createUser(randomUUID.toString(), "Test User", "TestPasswort123", "01.01.2000"); |
|
|
|
|
|
|
|
// Example of accessing properties |
|
|
|
System.out.println("UserID: " + user.getId()); |
|
|
@ -126,6 +146,8 @@ class CreateUser { |
|
|
|
|
|
|
|
// Save user information to a JSON file |
|
|
|
user.saveToJsonFile("user.json"); |
|
|
|
|
|
|
|
updateStayLoggedIn("user.json", "Test User", true); |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
System.out.println("Error: " + e.getMessage()); |
|
|
|
} |
|
|
|