From 23b0eb9244f09e935683f547de40a056f222eebb Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 12 May 2024 19:06:02 +0300 Subject: [PATCH] added the solution of task --- .../java/mate/academy/service/AuthenticationService.java | 7 +++++++ src/main/java/mate/academy/service/UserService.java | 8 +++++++- 2 files changed, 14 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..3c09be3f3 100644 --- a/src/main/java/mate/academy/service/AuthenticationService.java +++ b/src/main/java/mate/academy/service/AuthenticationService.java @@ -1,5 +1,7 @@ package mate.academy.service; +import mate.academy.model.User; + public class AuthenticationService { /** * Imagine that some user wants to login to your site. @@ -11,6 +13,11 @@ 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); + if (user != null && user.getPassword().equals(password)) { + return true; + } return false; } } diff --git a/src/main/java/mate/academy/service/UserService.java b/src/main/java/mate/academy/service/UserService.java index 1652d7d68..2c425dc4d 100644 --- a/src/main/java/mate/academy/service/UserService.java +++ b/src/main/java/mate/academy/service/UserService.java @@ -3,18 +3,24 @@ import mate.academy.model.User; public class UserService { - private static final User[] users = new User[] { + private static final User[] users = new User[]{ new User("bob@i.ua", "1234"), new User("alice@i.ua", "1234") }; /** * Find user by email. All users are stored in private static final User[] users + * * @param email - the input parameter * @return - user if his email is equal to passed email. * Return null if there is no suitable user */ public User findByEmail(String email) { + for (int i = 0; i < users.length; i++) { + if (users[i].getEmail().equals(email)) { + return users[i]; + } + } return null; } }