Refactor authentication and user service. Adding Tests for UserService.java and AuthenticationService.java
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -99,17 +99,18 @@ public class AuthenticationService {
|
||||
new UsernamePasswordAuthenticationToken(authPairDTO.getEmail(), authPairDTO.getPassword())
|
||||
);
|
||||
|
||||
User user = userRepository.findByEmail(authPairDTO.getEmail()).get();
|
||||
System.out.println(user.getEmail());
|
||||
User user = userRepository.findByEmail(authPairDTO.getEmail())
|
||||
.orElseThrow(() -> new RuntimeException("User not found"));
|
||||
|
||||
UserDTO userDTO = userMapper.toUserDTO(user);
|
||||
// TODO patch, commented out
|
||||
//UserDTO userDTO = new UserDTO(user.getId(), user.getUsername(), user.getRoles());
|
||||
|
||||
String token = tokenService.generateUserJwt(auth, userDTO);
|
||||
return new LoginResponseDTO(userDTO, token);
|
||||
|
||||
} catch (AuthenticationException e) {
|
||||
System.out.println("AuthenticationException: " + e.getMessage());
|
||||
//System.out.println("AuthenticationException: " + e.getMessage());
|
||||
return new LoginResponseDTO(null, "");
|
||||
} catch ( RuntimeException e) {
|
||||
return new LoginResponseDTO(null, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user