From 9f87b029e81c3175f8478edec7c8598895b1d9ba Mon Sep 17 00:00:00 2001 From: Mykhayl Date: Sat, 14 Oct 2023 21:33:29 +0300 Subject: [PATCH 1/3] the requested methods have been implemented --- .../java/mate/academy/service/AuthenticationService.java | 9 ++++++++- src/main/java/mate/academy/service/UserService.java | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8f7c7c975..8acb7eb46 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -1,6 +1,10 @@ package mate.academy.service; public class AuthenticationService { + private static final String BOB_EMAIL = "bob@i.ua"; + private static final String BOB_PASSWORD = "querty"; + private static final String DEFAULT_PASSWORD = "1234"; + /** * Imagine that some user wants to login to your site. * You should check if user credentials (login and password) are valid or not. @@ -11,6 +15,9 @@ public class AuthenticationService { * Return false in any other cases. */ public boolean login(String email, String password) { - return false; + if (BOB_EMAIL.equalsIgnoreCase(email)) { + return BOB_PASSWORD.equals(password); + } + return DEFAULT_PASSWORD.equals(password); } } diff --git a/src/main/java/mate/academy/service/UserService.java b/src/main/java/mate/academy/service/UserService.java index 1652d7d68..21a2820d0 100644 --- a/src/main/java/mate/academy/service/UserService.java +++ b/src/main/java/mate/academy/service/UserService.java @@ -15,6 +15,11 @@ public class UserService { * Return null if there is no suitable user */ public User findByEmail(String email) { + for (User user: users) { + if (user.getEmail().equalsIgnoreCase(email)) { + return user; + } + } return null; } } From 16471a90fd463c45151feadd8d69261e0610191f Mon Sep 17 00:00:00 2001 From: Mykhayl Date: Sun, 15 Oct 2023 16:54:33 +0300 Subject: [PATCH 2/3] UserService usage added. Please correct the task description to make it clear what exactly you are requesting to implement. Thank you! --- .../mate/academy/service/AuthenticationService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8acb7eb46..b570b32a9 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -1,9 +1,8 @@ package mate.academy.service; +import mate.academy.model.User; + public class AuthenticationService { - private static final String BOB_EMAIL = "bob@i.ua"; - private static final String BOB_PASSWORD = "querty"; - private static final String DEFAULT_PASSWORD = "1234"; /** * Imagine that some user wants to login to your site. @@ -15,9 +14,8 @@ public class AuthenticationService { * Return false in any other cases. */ public boolean login(String email, String password) { - if (BOB_EMAIL.equalsIgnoreCase(email)) { - return BOB_PASSWORD.equals(password); - } - return DEFAULT_PASSWORD.equals(password); + UserService userService = new UserService(); + User user = userService.findByEmail(email); + return (user != null && user.getPassword().equals(password)); } } From a5ce3dbccf0931f2f5b0b49299172483e7fd0c4c Mon Sep 17 00:00:00 2001 From: Mykhayl Date: Sun, 15 Oct 2023 21:34:51 +0300 Subject: [PATCH 3/3] User service added as a class field --- src/main/java/mate/academy/service/AuthenticationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index b570b32a9..797000e26 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -3,6 +3,7 @@ import mate.academy.model.User; public class AuthenticationService { + private final UserService userService = new UserService(); /** * Imagine that some user wants to login to your site. @@ -14,7 +15,6 @@ public class AuthenticationService { * Return false in any other cases. */ public boolean login(String email, String password) { - UserService userService = new UserService(); User user = userService.findByEmail(email); return (user != null && user.getPassword().equals(password)); }