use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceImpl method setLocale.
@Override
@Transactional
public void setLocale(Locale locale) {
UserDto currentUser = getCurrentUser();
MotechUser user = motechUsersDao.findByUserName(currentUser.getUserName());
user.setLocale(locale);
updateUserDetailsWithoutPassword(new UserDto(user));
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class PasswordExpirationCheckEventHandler method handleEvent.
/**
* Handles PASSWORD_EXPIRATION_CHECK_EVENT event. Checks every user for the date of the last password change and sends an
* event if the user should be notified about the required password change.
*
* @param event the event to be handled
*/
@MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT)
public void handleEvent(MotechEvent event) {
if (settingService.isPasswordResetReminderEnabled()) {
LOGGER.info("Daily password reset reminder triggered");
final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword();
final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder();
final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder;
for (MotechUser user : allUsers.retrieveAll()) {
final int daysWithoutPasswordChange = daysWithoutPasswordChange(user);
LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder);
if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) {
if (StringUtils.isNotBlank(user.getEmail())) {
sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder);
} else {
LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName());
}
}
}
} else {
LOGGER.info("Daily password reset reminder is disabled, skipping processing of users");
}
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechLoginErrorHandlerTest method createUser.
private MotechUser createUser(UserStatus userStatus, int failureLoginCounter) {
MotechUser user = new MotechUser();
user.setUserName("testUser");
user.setFailureLoginCounter(failureLoginCounter);
user.setUserStatus(userStatus);
return user;
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class PasswordExpirationCheckEventHandlerTest method prepareMotechUsersTwo.
private List<MotechUser> prepareMotechUsersTwo() {
List<MotechUser> users = new ArrayList<>();
DateTime date = DateUtil.now().minusDays(14);
MotechUser user = new MotechUser();
user.setUserName("fooUsernameOne");
user.setEmail("foouserone@foodomain.com");
user.setLastPasswordChange(date);
users.add(user);
user = new MotechUser();
user.setUserName("fooUsernameTwo");
user.setEmail("foousertwo@foodomain.com");
user.setLastPasswordChange(date);
users.add(user);
user = new MotechUser();
user.setUserName("fooUsernameThree");
user.setEmail("foouserthree@foodomain.com");
user.setLastPasswordChange(date.minusDays(2));
users.add(user);
user = new MotechUser();
user.setUserName("fooUsernameFour");
user.setEmail("foouserfour@foodomain.com");
user.setLastPasswordChange(date.minusDays(2));
users.add(user);
return users;
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class PasswordExpirationCheckEventHandlerTest method prepareMotechUsersOne.
private List<MotechUser> prepareMotechUsersOne() {
List<MotechUser> users = new ArrayList<>();
DateTime date = DateUtil.now().minusDays(14);
MotechUser user = new MotechUser();
user.setUserName("fooUsernameOne");
user.setEmail("foouserone@foodomain.com");
user.setLastPasswordChange(date);
users.add(user);
user = new MotechUser();
user.setUserName("fooUsernameTwo");
user.setEmail("foousertwo@foodomain.com");
user.setLastPasswordChange(date.minusDays(1));
users.add(user);
user = new MotechUser();
user.setUserName("fooUsernameThree");
user.setEmail("foouserthree@foodomain.com");
user.setLastPasswordChange(date.minusDays(1));
users.add(user);
user = new MotechUser();
user.setUserName("fooUsernameFour");
user.setEmail("foouserfour@foodomain.com");
user.setLastPasswordChange(date.minusDays(2));
users.add(user);
return users;
}
Aggregations