-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserList.java
86 lines (76 loc) · 2.05 KB
/
UserList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.ArrayList;
import java.util.UUID;
public class UserList {
private static UserList userList = null;
private static ArrayList<User> users = new ArrayList<>();
/**
* Constructor for the list of users
*/
public UserList() {
users = new ArrayList<User>();
users = DataLoader.GetUsers();
}
/**
* @return the instance of the userlist
*/
public static UserList getInstance() {
if(userList == null) {
userList = new UserList();
}
return userList;
}
/**
* @return the user in the userList
*/
public ArrayList<User> getUserList() {
return users;
}
/**
* Add user to the userList
* @param userName
* @param password
* @param firstName
* @param lastName
* @param email
* @param privacyLevel
*/
public static void addUser(String userName, String password, String firstName, String lastName, String email, int privacyLevel) {
users.add(new User(UUID.randomUUID(),userName, password, firstName, lastName, email, privacyLevel));
}
/**
* Check if user is valid
* @param userName
* @param password
* @return true if the user match the parameters
*/
public static boolean isValidLogin(String userName, String password) {
for(User user : users) {
if(user.getUserName().equals(userName) && user.getPassword().equals(password)) {
return true;
}
}
return false;
}
/**
* Get user from the userList
* @param userName
* @return the user
*/
public static User getUser(String userName) {
for(User user : users) {
if(user.getUserName().equals(userName)) {
return user;
}
}
return null;
}
/**
* logs out user and writers user info
*/
public void logout() {
DataWriter.saveUsers();
DataWriter.saveProjects();
DataWriter.saveTasks();
System.exit(0);
}
}