From f44af86cb54269e0b8869e0df4689c690ba0b0bc Mon Sep 17 00:00:00 2001 From: Volodymyr Nyshta Date: Sat, 17 Aug 2024 00:00:04 +0300 Subject: [PATCH] les_0 done --- .../java/mate/academy/service/AuthenticationService.java | 7 +++++++ src/main/java/mate/academy/service/UserService.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8f7c7c975..a80b6ffb8 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 userServ = new UserService(); + User user = userServ.findByEmail(email); + if (user != null && user.getPassword() == 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..ae415abbe 100644 --- a/src/main/java/mate/academy/service/UserService.java +++ b/src/main/java/mate/academy/service/UserService.java @@ -15,6 +15,13 @@ public class UserService { * Return null if there is no suitable user */ public User findByEmail(String email) { + if (email != null) { + for (int i = 0; i < users.length; i++) { + if (users[i].getEmail() == email) { + return users[i]; + } + } + } return null; } }