-
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
login method and findByEmail method added #1143
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, some comments 👇
@@ -15,6 +15,11 @@ public class UserService { | |||
* Return <code>null</code> if there is no suitable user | |||
*/ | |||
public User findByEmail(String email) { | |||
for (User tempUser: users) { |
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.
for (User tempUser: users) { | |
for (User user : users) { |
use space before and after semicolon
return true; | ||
} | ||
} | ||
System.out.println("No user with this e-mail is found"); |
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 forget to remove sout (system.out.println) from your solution before committing your HW
@@ -11,6 +13,14 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService serv = new 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 shorten your local variables' names, be verbose! 🙏 Remember, developers spend much more time reading the code of others than writing their own, time saved by not typing out a few extra letters is not worth it
@@ -11,6 +13,14 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService serv = new 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.
UserService serv = new UserService(); | |
UserService userService = new UserService(); |
User user = serv.findByEmail(email); | ||
if (user != null) { | ||
if (user.getPassword().equals(password)) { | ||
return true; | ||
} | ||
} | ||
System.out.println("No user with this e-mail is found"); | ||
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.
try to rewrite this solution without using boolean literals (true/false) at all. Use logical expressions directly in return
a whitespace before and after semicolon added variable names changed to be more descriptive System.out.println removed
@@ -1,5 +1,7 @@ | |||
package mate.academy.service; | |||
|
|||
import mate.academy.model.User; | |||
|
|||
public class AuthenticationService { |
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 class AuthenticationService { | |
public class AuthenticationService { | |
private final UserService userService = new 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.
I receive the message: "Modifier 'private' is not allowed here"
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.
@@ -11,6 +13,13 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService newService = new 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.
UserService newService = new UserService(); |
Co-authored-by: Olena Bruiako <[email protected]>
return false; | ||
final UserService newService = new UserService(); | ||
User user = newService.findByEmail(email); | ||
return user != null && user.getPassword().equals(password)); |
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.
return user != null && user.getPassword().equals(password)); | |
return user != null && user.getPassword().equals(password); |
@@ -1,5 +1,7 @@ | |||
package mate.academy.service; | |||
|
|||
import mate.academy.model.User; | |||
|
|||
public class AuthenticationService { |
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.
for (User temporalUser : users) { | ||
if (temporalUser.getEmail().equals(email)) { | ||
return temporalUser; |
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.
for (User temporalUser : users) { | |
if (temporalUser.getEmail().equals(email)) { | |
return temporalUser; | |
for (User user : users) { | |
if (user.getEmail().equals(email)) { | |
return user; |
No description provided.