use of com.axelor.auth.AuthService in project axelor-open-suite by axelor.
the class UserServiceImpl method generateRandomPasswordForUsers.
@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public void generateRandomPasswordForUsers(List<Long> userIds) {
AuthService authService = Beans.get(AuthService.class);
LocalDateTime todayDateTime = Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime();
for (Long userId : userIds) {
User user = userRepo.find(userId);
String password = this.generateRandomPassword().toString();
user.setTransientPassword(password);
password = authService.encrypt(password);
user.setPassword(password);
user.setPasswordUpdatedOn(todayDateTime);
userRepo.save(user);
}
// Update login date in session so that user changing own password doesn't get logged out.
if (userIds.contains(getUserId())) {
Session session = AuthUtils.getSubject().getSession();
session.setAttribute("loginDate", todayDateTime);
}
}
use of com.axelor.auth.AuthService in project axelor-open-suite by axelor.
the class UserServiceImpl method verifyCurrentUserPassword.
@Override
public boolean verifyCurrentUserPassword(String password) {
if (!StringUtils.isBlank(password)) {
final User current = AuthUtils.getUser();
final AuthService authService = AuthService.getInstance();
if (authService.match(password, current.getPassword())) {
return true;
}
}
return false;
}
use of com.axelor.auth.AuthService in project axelor-open-suite by axelor.
the class UserServiceImpl method changeUserPassword.
@Override
public User changeUserPassword(User user, Map<String, Object> values) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, AxelorException {
Preconditions.checkNotNull(user, I18n.get("User cannot be null."));
Preconditions.checkNotNull(values, I18n.get("User context cannot be null."));
final String oldPassword = (String) values.get("oldPassword");
final String newPassword = (String) values.get("newPassword");
final String chkPassword = (String) values.get("chkPassword");
// no password change
if (StringUtils.isBlank(newPassword)) {
return user;
}
if (StringUtils.isBlank(oldPassword)) {
throw new ValidationException(I18n.get("Current user password is not provided."));
}
if (!newPassword.equals(chkPassword)) {
throw new ValidationException(I18n.get("Confirm password doesn't match with new password."));
}
if (!matchPasswordPattern(newPassword)) {
throw new ValidationException(I18n.get(PATTERN_DESCRIPTION));
}
final User current = AuthUtils.getUser();
final AuthService authService = AuthService.getInstance();
if (!authService.match(oldPassword, current.getPassword())) {
throw new ValidationException(I18n.get("Current user password is wrong."));
}
user.setTransientPassword(newPassword);
return user;
}
Aggregations