File tree Expand file tree Collapse file tree 2 files changed +2
-5
lines changed
src/main/java/mate/academy Expand file tree Collapse file tree 2 files changed +2
-5
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,10 @@ public User get(Long id) {
43
43
@ Override
44
44
public Optional <User > findByEmail (String email ) {
45
45
try (Session session = HibernateUtil .getSessionFactory ().openSession ()) {
46
- Query <User > query = session .createQuery ("from User, User.class where email"
46
+ Query <User > query = session .createQuery ("from User where email"
47
47
+ "=:email" );
48
48
query .setParameter ("email" , email );
49
- return Optional . ofNullable ( query .uniqueResult () );
49
+ return query .uniqueResultOptional ( );
50
50
} catch (Exception exception ) {
51
51
throw new RuntimeException ("Cannot get user" , exception );
52
52
}
Original file line number Diff line number Diff line change @@ -16,9 +16,6 @@ public class AuthenticationServiceImpl implements AuthenticationService {
16
16
@ Override
17
17
public User login (String email , String password ) throws AuthenticationException {
18
18
Optional <User > byEmail = userService .findByEmail (email );
19
- if (byEmail .isEmpty ()) {
20
- throw new AuthenticationException ("Invalid email" );
21
- }
22
19
User user = byEmail .get ();
23
20
String hashedPassword = HashUtil .hashPassword (password , user .getSalt ());
24
21
if (!hashedPassword .equals (user .getPassword ()) || byEmail .isEmpty ()) {
You can’t perform that action at this time.
0 commit comments