-
Notifications
You must be signed in to change notification settings - Fork 936
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
base: master
Are you sure you want to change the base?
update #1151
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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();
if (checkEmailAndPassword(password, email)) { | ||
return true; | ||
} |
There was a problem hiding this comment.
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.
for (User tempUser : users) { | ||
if (!tempUser.getEmail().equals(email)) { | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
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?
public boolean checkEmailAndPassword(String password, String email) { | ||
for (User tempUser : users) { | ||
if (tempUser.getPassword().equals(password) && tempUser.getEmail().equals(email)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this method
i fixed the mistakes |
There was a problem hiding this 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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public User checkingPassword(String password) { | ||
for (User tempUser : users) { | ||
if (tempUser.getPassword().equals(password)) { | ||
return tempUser; | ||
} | ||
} |
There was a problem hiding this comment.
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> | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* |
@@ -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[]{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
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
if (service.findByEmail(email) != null) { | ||
return service.findByEmail(email).getPassword().equals(password); | ||
} | ||
return false; |
There was a problem hiding this comment.
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 &&)
No description provided.