-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthService.java
More file actions
29 lines (26 loc) · 844 Bytes
/
AuthService.java
File metadata and controls
29 lines (26 loc) · 844 Bytes
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
package services;
import models.*;
import java.util.*;
public class AuthService {
static List<User> users = new ArrayList<>();
static int userIdCounter = 1;
public static User register(String name, String email, String password, String role) {
for (User u : users) {
if (u.email.equals(email)) {
System.out.println("Email already exists!");
return null;
}
}
User user = new User(userIdCounter++, name, email, password, role);
users.add(user);
return user;
}
public static User login(String email, String password) {
for (User u : users) {
if (u.email.equals(email) && u.password.equals(password)) {
return u;
}
}
return null;
}
}