use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class JwtTokenEnhancer method enhance.
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
User user = userRepository.findByEmail(authentication.getName());
Map<String, Object> map = new HashMap<>();
map.put("userFirstName", user.getFirstName());
map.put("userId", user.getId());
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
token.setAdditionalInformation(map);
return accessToken;
}
use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class UserUpdateValidator method isValid.
@Override
public boolean isValid(UserUpdateDTO dto, ConstraintValidatorContext context) {
@SuppressWarnings("unchecked") var uriVars = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
long userId = Long.parseLong(uriVars.get("id"));
List<FieldMessage> list = new ArrayList<>();
User user = repository.findByEmail(dto.getEmail());
if (user != null && userId != user.getId()) {
list.add(new FieldMessage("email", "Email já existe"));
}
for (FieldMessage e : list) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(e.getMessage()).addPropertyNode(e.getFieldName()).addConstraintViolation();
}
return list.isEmpty();
}
use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class UserService method update.
@Transactional
public UserDTO update(Long id, UserUpdateDTO dto) {
try {
User entity = repository.getOne(id);
copyDtoToEntity(dto, entity);
entity = repository.save(entity);
return new UserDTO(entity);
} catch (EntityNotFoundException e) {
throw new ResourceNotFoundException("Id not found " + id);
}
}
use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class UserService method findById.
@Transactional(readOnly = true)
public UserDTO findById(Long id) {
authService.validateSelfOrAdmin(id);
Optional<User> obj = repository.findById(id);
User entity = obj.orElseThrow(() -> new ResourceNotFoundException("Entity not found"));
return new UserDTO(entity);
}
use of com.rafaelvieira.letmebuy.entities.User in project letmebuy by rafaelrok.
the class UserService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = repository.findByEmail(username);
if (user == null) {
logger.error("User not found: " + username);
throw new UsernameNotFoundException("Email not found");
}
logger.info("User found: " + username);
return user;
}
Aggregations