forked from deHank/AssignmentRepoDemo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserService.java
More file actions
42 lines (32 loc) · 1.34 KB
/
UserService.java
File metadata and controls
42 lines (32 loc) · 1.34 KB
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
import java.util.HashMap;
import java.util.Map;
public class UserService {
private Map<String, String> userDatabase = new HashMap<>();
private Map<String, Boolean> activeSessions = new HashMap<>();
public void register(String username, String password) {
userDatabase.put(username, password);
activeSessions.put(username, false);
}
public boolean login(String username, String password) {
if (username == null || password == null || username.isEmpty() || password.isEmpty())
return false;
if (!userDatabase.containsKey(username)) return false;
if (activeSessions.getOrDefault(username, false)) return false;
if (!userDatabase.get(username).equals(password)) return false;
activeSessions.put(username, true);
return true;
}
public boolean isUserLoggedIn(String username) {
return activeSessions.getOrDefault(username, false);
}
public String getAdherenceData(String username) {
if (isUserLoggedIn(username)) return "AdherenceData";
return null;
}
public String getRedirectPage(String username) {
return isUserLoggedIn(username) ? "dashboard" : "login";
}
public boolean authenticate(String username, String password) {
return username.equals("alice") && password.equals("Secret123");
}
}