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

login and findByEmail #1150

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

login and findByEmail #1150

wants to merge 5 commits into from

Conversation

MishaHMK
Copy link

No description provided.

Copy link

@Elena-Bruyako Elena-Bruyako left a comment

Choose a reason for hiding this comment

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

Please, check build before sending the PR
Let's fix it

Comment on lines 11 to 14
public static User[] getUsers() {
return users;
}

Choose a reason for hiding this comment

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

Suggested change
public static User[] getUsers() {
return users;
}

Copy link
Author

Choose a reason for hiding this comment

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

I see, I didn't think about iteraction btwn findByEmail and login

public boolean login(String email, String password) {
for(User user : UserService.getUsers()){

Choose a reason for hiding this comment

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

create UserService as class-level variable
don't need to use for loop here

public boolean login(String email, String password) {
for(User user : UserService.getUsers()){
if(user.getEmail().equals(email) && user.getPassword().equals(password)){

Choose a reason for hiding this comment

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

you can use ternary operator here

public boolean login(String email, String password) {
return false;
User user = service.findByEmail(email);
return user != null && user.getPassword().equals(password) ? true : false;

Choose a reason for hiding this comment

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

Suggested change
return user != null && user.getPassword().equals(password) ? true : false;
return user != null && user.getPassword().equals(password);

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.

3 participants