Skip to content

Commit

Permalink
Added UserService field to AuthenticationService
Browse files Browse the repository at this point in the history
  • Loading branch information
misha-levko committed Jan 5, 2024
1 parent 58440a4 commit e14ff37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import mate.academy.model.User;

public class AuthenticationService {
private final UserService userService;

public AuthenticationService() {
this.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 @@ -12,8 +18,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) {
User user = UserService.findByEmail(email);
User user = userService.findByEmail(email);
return user != null && user.getPassword().equals(password);
}
}
3 changes: 2 additions & 1 deletion src/main/java/mate/academy/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class UserService {
* @return - user if his email is equal to passed email.
* Return <code>null</code> if there is no suitable user
*/
public static User findByEmail(String email) {

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

0 comments on commit e14ff37

Please sign in to comment.