-
Notifications
You must be signed in to change notification settings - Fork 935
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
Authentification service branch #1067
base: master
Are you sure you want to change the base?
Authentification service branch #1067
Conversation
@@ -11,6 +13,13 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService user = 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 user = new UserService(); | |
UserService userService = new UserService(); |
@@ -11,6 +13,13 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService user = 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.
create object outside of method
@@ -11,6 +13,13 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
UserService user = new UserService(); | |||
User found = user.findByEmail(email); |
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.
User found = user.findByEmail(email); | |
User user = userService.findByEmail(email); |
if (found != null) { | ||
if (found.getPassword().equals(password)) { | ||
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.
simplify it using one return
@@ -15,6 +15,11 @@ public class UserService { | |||
* Return <code>null</code> if there is no suitable user | |||
*/ | |||
public User findByEmail(String email) { | |||
for (User i: 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 i: users) { | |
for (User user : 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.
not fixed, rename variable
@@ -11,6 +13,9 @@ public class AuthenticationService { | |||
* Return false in any other cases. | |||
*/ | |||
public boolean login(String email, String password) { | |||
return false; | |||
UserService userService = new UserService(); | |||
User userToCheck = userService.findByEmail(email); |
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.
User userToCheck = userService.findByEmail(email); | |
User user = userService.findByEmail(email); |
@@ -15,6 +15,11 @@ public class UserService { | |||
* Return <code>null</code> if there is no suitable user | |||
*/ | |||
public User findByEmail(String email) { | |||
for (User i: 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.
not fixed, rename variable
@@ -10,7 +12,15 @@ public class AuthenticationService { | |||
* @return true if user by email exists and passed password is equal to user's password. | |||
* Return false in any other cases. | |||
*/ | |||
private 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.
private UserService userService = new UserService(); | |
private final UserService userService = new UserService(); |
public UserService getUserService() { | ||
return 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.
public UserService getUserService() { | |
return userService; | |
} |
public boolean login(String email, String password) { | ||
return false; | ||
User userToCheck = getUserService().findByEmail(email); |
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.
User userToCheck = getUserService().findByEmail(email); | |
User user =userService.findByEmail(email); |
@@ -10,7 +12,17 @@ public class AuthenticationService { | |||
* @return true if user by email exists and passed password is equal to user's password. | |||
* Return false in any other cases. | |||
*/ | |||
private final UserService userService = new UserService(); | |||
|
|||
public UserService getUserService() { |
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.
Why do you need this get method?
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.
to get the variable, Intellij IDEA indicated that it is better to make UserService object private and to get it I created the get method
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.
Not all advice from Idea should be implemented
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 get method
@@ -10,7 +12,17 @@ public class AuthenticationService { | |||
* @return true if user by email exists and passed password is equal to user's password. | |||
* Return false in any other cases. | |||
*/ | |||
private final UserService userService = new UserService(); | |||
|
|||
public UserService getUserService() { |
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 get method
public boolean login(String email, String password) { | ||
return false; | ||
User user = getUserService().findByEmail(email); |
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.
User user = getUserService().findByEmail(email); | |
User user = userService.findByEmail(email); |
@@ -10,7 +12,17 @@ public class AuthenticationService { | |||
* @return true if user by email exists and passed password is equal to user's password. | |||
* Return false in any other cases. | |||
*/ | |||
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.
Your code should look like
private final UserService userService = new UserService(); | |
private final UserService userService = new UserService(); | |
public boolean login(String email, String password) { | |
User user = userService.findByEmail(email); | |
return user != null && user.getPassword().equals(password); | |
} |
No description provided.