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 method and findByEmail method added #1143

Closed
wants to merge 5 commits into from

Conversation

ira-levch
Copy link

No description provided.

Copy link

@okuzan okuzan 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, 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) {
Copy link

Choose a reason for hiding this comment

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

Suggested change
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");
Copy link

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();
Copy link

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();
Copy link

Choose a reason for hiding this comment

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

Suggested change
UserService serv = new UserService();
UserService userService = new UserService();

Comment on lines 17 to 24
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;
Copy link

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
@ira-levch ira-levch requested a review from okuzan December 10, 2024 12:53
@@ -1,5 +1,7 @@
package mate.academy.service;

import mate.academy.model.User;

public class AuthenticationService {

Choose a reason for hiding this comment

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

Suggested change
public class AuthenticationService {
public class AuthenticationService {
private final UserService userService = new UserService();

Copy link
Author

@ira-levch ira-levch Dec 10, 2024

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"

Choose a reason for hiding this comment

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

There is no any error messages
Screenshot 2024-12-10 at 17 51 17

@@ -11,6 +13,13 @@ public class AuthenticationService {
* Return false in any other cases.
*/
public boolean login(String email, String password) {
UserService newService = new UserService();

Choose a reason for hiding this comment

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

Suggested change
UserService newService = new UserService();

return false;
final UserService newService = new UserService();
User user = newService.findByEmail(email);
return user != null && user.getPassword().equals(password));

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));
return user != null && user.getPassword().equals(password);

@@ -1,5 +1,7 @@
package mate.academy.service;

import mate.academy.model.User;

public class AuthenticationService {

Choose a reason for hiding this comment

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

There is no any error messages
Screenshot 2024-12-10 at 17 51 17

Comment on lines +18 to +20
for (User temporalUser : users) {
if (temporalUser.getEmail().equals(email)) {
return temporalUser;

Choose a reason for hiding this comment

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

Suggested change
for (User temporalUser : users) {
if (temporalUser.getEmail().equals(email)) {
return temporalUser;
for (User user : users) {
if (user.getEmail().equals(email)) {
return user;

@ira-levch ira-levch closed this by deleting the head repository Dec 30, 2024
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