From 45c39fc804f70b8f65a0b766327135d3aa11cf29 Mon Sep 17 00:00:00 2001 From: Bohdan Chupika Date: Fri, 22 Sep 2023 13:38:53 +0300 Subject: [PATCH] create HW --- .github/workflows/ci.yml | 4 ++-- .../mate/academy/service/AuthenticationService.java | 10 ++++++++++ src/main/java/mate/academy/service/UserService.java | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ead0ef36a..282f50ac5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'adopt' cache: maven - name: Build with Maven diff --git a/src/main/java/mate/academy/service/AuthenticationService.java b/src/main/java/mate/academy/service/AuthenticationService.java index 8f7c7c975..9e5393c4a 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. @@ -10,7 +12,15 @@ 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. */ + private UserService service = new UserService(); + public boolean login(String email, String password) { + User user = service.findByEmail(email); + if (user == null) { + return false; + } else if (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..94210665c 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().equals(email)) { + return user; + } + } return null; } }