Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #1151

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

update #1151

wants to merge 6 commits into from

Conversation

PIpatii
Copy link

@PIpatii PIpatii commented Dec 15, 2024

No description provided.

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Let’s improve your solution ;)

@@ -1,16 +1,21 @@
package mate.academy.service;

public class AuthenticationService {
public class AuthenticationService extends UserService {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t use inheritance here. if you want to use some method of UserService you should create an instance
private final UserService service = new UserService();

Comment on lines 15 to 17
if (checkEmailAndPassword(password, email)) {
return true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify this method. Use findByEmail and if user != null compare passwords.

Comment on lines 19 to 23
for (User tempUser : users) {
if (!tempUser.getEmail().equals(email)) {
break;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method returns null in any case. Is it expected behavior?

Comment on lines 27 to 34
public boolean checkEmailAndPassword(String password, String email) {
for (User tempUser : users) {
if (tempUser.getPassword().equals(password) && tempUser.getEmail().equals(email)) {
return true;
}
}
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this method

@PIpatii PIpatii closed this Dec 18, 2024
@PIpatii PIpatii reopened this Dec 18, 2024
@PIpatii
Copy link
Author

PIpatii commented Dec 18, 2024

i fixed the mistakes

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Let's fix a few mistakes ;)

return false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 27 to 32
public User checkingPassword(String password) {
for (User tempUser : users) {
if (tempUser.getPassword().equals(password)) {
return tempUser;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code. remove this method and use findByEmail instead of this method

new User("[email protected]", "1234"),
new User("[email protected]", "1234")
};

/**
* Find user by email. All users are stored in <code>private static final User[] users</code>
*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*

@@ -3,18 +3,33 @@
import mate.academy.model.User;

public class UserService {
private static final User[] users = new User[] {
private static final User[] users = new User[]{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final User[] users = new User[]{
private static final User[] users = new User[] {

public boolean login(String email, String password) {
if (service.findByEmail(email) != null) {
return service.checkingPassword(password) != null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you should check that the input password equals the password of the user that returns the findByEmail method call

Comment on lines 17 to 20
if (service.findByEmail(email) != null) {
return service.findByEmail(email).getPassword().equals(password);
}
return false;
Copy link

@okuzan okuzan Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you call findByEmal twice. save the result of the single call to a local variable, and reuse it. Try to use only one return in this method (combine conditions with &&)

@PIpatii PIpatii requested a review from okuzan December 22, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants