use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method resetPassword.
@Override
public void resetPassword(String userEmail) {
UserEntity user = null;
try {
user = userRepository.findUserByEmail(userEmail).get();
} catch (NoSuchElementException e) {
throw new CustomParameterizedException(i18n.translate("email.emailUserNotFound"));
} catch (Exception ex) {
throw new CustomParameterizedException(i18n.translate("email.errorResetMail"));
}
if (user == null) {
throw new CustomParameterizedException(i18n.translate("email.emailUserNotFound"));
}
String token = UUID.randomUUID().toString();
createPasswordResetTokenForUser(user, token);
SimpleMailMessage template = new SimpleMailMessage();
template.setText(loadTemplate(applicationProps.getTemplates().getResetMail()));
String[] args = { i18n.translate("email.bodyTitle"), i18n.translate("email.bodyGreeting"), applicationProps.getClient().getLoginUrl() + "?" + MAIL_PARAM_TOKEN + "=" + token + "&" + MAIL_PARAM_ID + "=" + user.getId(), i18n.translate("email.bodyReset", user.getEmail()), i18n.translate("email.bodySign") };
emailService.sendSimpleMessageUsingTemplate(user.getEmail(), i18n.translate("email.resetPassword"), template, args);
}
use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserDetailsServiceImpl method loadUserByUsername.
@Override
public UserDetailsDTO loadUserByUsername(String username) throws UsernameNotFoundException {
LOG.info("Loading user details: {}", username);
UserEntity user = userRepository.findOneByUsername(username).orElseThrow(() -> new UsernameNotFoundException("Username not found " + username));
List<UserRoleEntity> roles = userRoleRepo.findByUser(user);
UserApplicationEntity userApp = userApplicationRepo.findByUser(user).orElseGet(UserApplicationEntity::new);
Optional<OrganizationEntity> organization = userApp.getOrganizationOpt();
Optional<ApplicationEntity> application = userApp.getApplicationOpt();
return UserDetailsDTO.builder().username(user.getUsername()).password(user.getPass()).enabled(user.isActive()).application(application.map(applicationMapper::entityToDto).orElse(null)).organization(organization.map(organizationMapper::entityToDto).orElse(null)).grantedAuthorities(this.getGrantedAuthorities(roles)).build();
}
use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserServiceImpl method addUser.
@Override
public UserDTO addUser(UserDTO userDTO) {
userRepository.findOneByUsername(userDTO.getUsername()).ifPresent(user -> {
throw new CustomParameterizedException("User already exists.", new ImmutableMultimap.Builder<String, String>().put("username", user.getUsername()).build().asMap());
});
UserEntity user = new UserEntity();
BeanUtils.copyProperties(userDTO, user);
UserEntity newUser = userRepository.save(user);
return userMapper.entityToDto(newUser);
}
use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotEconomicMapper method newSnapshotToEconomicEntity.
public SnapshotEconomicEntity newSnapshotToEconomicEntity(NewSnapshot snapshot, SnapshotIndicatorEntity indicator) {
UserEntity user = null;
TermCondPolEntity termCond = null;
TermCondPolEntity privPol = null;
if (snapshot.getUserName() != null) {
user = userRepository.findOneByUsername(snapshot.getUserName()).get();
}
if (snapshot.getTermCondId() != null) {
termCond = termCondPolRepository.findOne(snapshot.getTermCondId());
}
if (snapshot.getPrivPolId() != null) {
privPol = termCondPolRepository.findOne(snapshot.getPrivPolId());
}
return new SnapshotEconomicEntity().surveyDefinition(new SurveyEntity(snapshot.getSurveyId())).surveyIndicator(indicator).staticProperties(snapshot.getMappedEconomicSurveyData(propertyAttributeSupport.staticEconomic(), propertyAttributeSupport::propertySchemaToSystemName)).additionalProperties(snapshot.getEconomicSurveyData(propertyAttributeSupport.additional())).user(user).termCond(termCond).privPol(privPol);
}
use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotDraftServiceImpl method getSnapshotDraftByUser.
public List<SnapshotDraft> getSnapshotDraftByUser(UserDetailsDTO details, String familyName) {
UserEntity user = userRepository.findOneByUsername(details.getUsername()).orElse(null);
if (user == null) {
return Collections.emptyList();
}
List<SnapshotDraftEntity> draftList = repository.findAll(where(userEquals(user.getId())).and(likeFamilyName(familyName)).and(createdAtLessDays(SNAPSHOT_DRAFT_MAX_DAY)));
return mapper.entityListToDtoList(draftList);
}
Aggregations