use of it.istat.mec.users.domain.UsersEntity in project catalogo-strumenti by istat-methodology.
the class UserService method updateUser.
public String updateUser(Integer id, UpdateUserRequest request) throws Exception {
String msg = "";
if (!usersDao.findById(id).isPresent())
throw new NoDataException("User not present");
UsersEntity user = usersDao.findById(id).get();
user = Translators.translateUpdate(request, user);
if (request.getRoleid() != null) {
if (!userRolesDao.findById(request.getRoleid()).isPresent())
throw new NoDataException("Role not present");
UserRolesEntity userRole = userRolesDao.findById(request.getRoleid()).get();
user.setRole(userRole);
}
usersDao.save(user);
msg = "User succesfully updated!";
return msg;
}
use of it.istat.mec.users.domain.UsersEntity in project catalogo-strumenti by istat-methodology.
the class UserService method resetPasswordById.
public String resetPasswordById(Integer id, ResetPasswordRequest request) throws Exception {
String msg = "";
if (!usersDao.findById(id).isPresent())
throw new NoDataException("User not present");
UsersEntity user = usersDao.findById(id).get();
if ((request.getPassword() != null && !request.getPassword().equals(""))) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String newPass = passwordEncoder.encode(request.getPassword());
user.setPassword(newPass);
usersDao.save(user);
msg = "01 Password succesfully updated!";
} else {
msg = "02 The password field is mandatory";
}
usersDao.save(user);
return msg;
}
use of it.istat.mec.users.domain.UsersEntity in project catalogo-strumenti by istat-methodology.
the class Translators method translate.
public static UsersEntity translate(CreateUserRequest x) {
final ModelMapper modelMapper = new ModelMapper();
final UsersEntity user = modelMapper.map(x, UsersEntity.class);
return user;
}
use of it.istat.mec.users.domain.UsersEntity in project catalogo-strumenti by istat-methodology.
the class UserService method updatePasswordByEmail.
public String updatePasswordByEmail(String email, UpdatePasswordRequest request) throws Exception {
String msg = "";
if (!usersDao.findByEmail(email).isPresent())
throw new NoDataException("User not present");
UsersEntity user = usersDao.findByEmail(email).get();
if ((request.getNewpass() != null && !request.getNewpass().equals("")) && (request.getOldpass() != null && !request.getOldpass().equals(""))) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String newPass = passwordEncoder.encode(request.getNewpass());
if (passwordEncoder.matches(request.getOldpass(), user.getPassword())) {
user.setPassword(newPass);
usersDao.save(user);
msg = "01 Password succesfully updated!";
} else {
msg = "02 The old password doesn't match with password stored in db";
}
} else {
msg = "03 The Old password and New password fields are mandatory";
}
usersDao.save(user);
return msg;
}
use of it.istat.mec.users.domain.UsersEntity in project catalogo-strumenti by istat-methodology.
the class UserService method updatePasswordById.
public String updatePasswordById(Integer id, UpdatePasswordRequest request) throws Exception {
String msg = "";
if (!usersDao.findById(id).isPresent())
throw new NoDataException("User not present");
UsersEntity user = usersDao.findById(id).get();
if ((request.getNewpass() != null && !request.getNewpass().equals("")) && (request.getOldpass() != null && !request.getOldpass().equals(""))) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String newPass = passwordEncoder.encode(request.getNewpass());
if (passwordEncoder.matches(request.getOldpass(), user.getPassword())) {
user.setPassword(newPass);
usersDao.save(user);
msg = "01 Password succesfully updated!";
} else {
msg = "02 The old password doesn't match with password stored in db";
}
} else {
msg = "03 The Old password and New password fields are mandatory";
}
usersDao.save(user);
return msg;
}
Aggregations