Browse Source

Added a boolean value along getter and setter methods to CreateUser that later checks if the user wants to stay logged in

remotes/origin/server
Richard Schmidt 11 months ago
parent
commit
cec86a85d8
  1. 9
      src/main/java/CreateUser.java
  2. 8
      src/main/java/LoginGUI.java
  3. 32
      user.json

9
src/main/java/CreateUser.java

@ -17,6 +17,7 @@ class CreateUser {
private String userName; private String userName;
private String password; private String password;
private String birthday; private String birthday;
private boolean stayLoggedIn;
// Constructor // Constructor
@ -59,6 +60,14 @@ class CreateUser {
public void setBirthday(String birthday) { public void setBirthday(String birthday) {
this.birthday = birthday; this.birthday = birthday;
} }
public boolean isStayLoggedIn() {
return stayLoggedIn;
}
public void setStayLoggedIn(boolean stayLoggedIn) {
this.stayLoggedIn = stayLoggedIn;
}
// Function to create user with validation // Function to create user with validation
public static CreateUser createUser(String id, String userName, String password, String birthday) { public static CreateUser createUser(String id, String userName, String password, String birthday) {

8
src/main/java/LoginGUI.java

@ -44,6 +44,8 @@ public class LoginGUI extends JFrame implements ActionListener {
getRootPane().setDefaultButton(loginButton); getRootPane().setDefaultButton(loginButton);
passwordField.addKeyListener(new EnterKeyListener());
} }
@Override @Override
@ -56,6 +58,7 @@ public class LoginGUI extends JFrame implements ActionListener {
private void login() { private void login() {
String username = usernameField.getText(); String username = usernameField.getText();
String password = new String(passwordField.getPassword()); String password = new String(passwordField.getPassword());
boolean stayLoggedIn = stayLoggedInCheckbox.isSelected(); // Get checkbox state
if (authenticateUser(username, password)) { if (authenticateUser(username, password)) {
JOptionPane.showMessageDialog(this, "Login successful!"); JOptionPane.showMessageDialog(this, "Login successful!");
@ -67,6 +70,11 @@ public class LoginGUI extends JFrame implements ActionListener {
} }
} }
private void updateStayLoggedIn(String username, boolean stayLoggedIn) {
// Update stayLoggedIn in the JSON file for the user
}
// Function to authenticate the user by comparing the entered username and password with the saved user data // Function to authenticate the user by comparing the entered username and password with the saved user data
private boolean authenticateUser(String username, String password) { private boolean authenticateUser(String username, String password) {
List<CreateUser> userList = CreateUser.readUserListFromJsonFile("user.json"); List<CreateUser> userList = CreateUser.readUserListFromJsonFile("user.json");

32
user.json

@ -1,32 +1,16 @@
[ [
{ {
"id": "961ca202-ecbd-4dfc-ac0b-28f367618aa1",
"userName": "asd",
"password": "123456",
"birthday": "1"
},
{
"id": "d563a466-753b-4a5e-8b6c-e7e4756c7397",
"userName": "asd1",
"password": "123456",
"birthday": "1"
},
{
"id": "b54391dc-c06b-496c-828a-501f9a182cf9",
"userName": "new user",
"password": "123456",
"birthday": "1"
},
{
"id": "6db2ea00-246d-4604-bef2-0875c3cb550e",
"id": "a2864d79-1079-4cbb-8d77-f5f84995580d",
"userName": "Another Test User", "userName": "Another Test User",
"password": "TestPasswort123", "password": "TestPasswort123",
"birthday": "01.01.2000"
"birthday": "01.01.2000",
"stayLoggedIn": false
}, },
{ {
"id": "864695a6-8037-41e5-9f0e-4b92744b2113",
"userName": "Another Test User",
"password": "TestPasswort123",
"birthday": "01.01.2000"
"id": "3690702d-9c7e-48fb-8a01-ef89b3b76268",
"userName": "TestUser2",
"password": "123456",
"birthday": "01.01.2000",
"stayLoggedIn": false
} }
] ]
Loading…
Cancel
Save