Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package mate.academy.service;

import mate.academy.model.User;

public class AuthenticationService {
private UserService userService = new UserService();
/**
* Imagine that some user wants to login to your site.
* You should check if user credentials (login and password) are valid or not.
Expand All @@ -10,7 +13,9 @@ public class AuthenticationService {
* @return true if user by email exists and passed password is equal to user's password.
* Return false in any other cases.
*/

public boolean login(String email, String password) {
return false;
User user = userService.findByEmail(email);
return user != null && user.getPassword().equals(password);
}
}
13 changes: 11 additions & 2 deletions src/main/java/mate/academy/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
import mate.academy.model.User;

public class UserService {
private static final User[] users = new User[] {
static final User[] users = new User[] {
new User("[email protected]", "1234"),
new User("[email protected]", "1234")
};

/**
* Find user by email. All users are stored in <code>private static final User[] users</code>
* @param email - the input parameter
* @parameter email - the input parameter
* @return - user if his email is equal to passed email.
* Return <code>null</code> if there is no suitable user
*/
public User[] getUsers() {
return users;
}

public User findByEmail(String email) {
for (User user : users) {
if (user.getEmail().equals(email)) {
return user;
}
}
return null;
}
}