use of org.mifos.security.util.UserContext in project head by mifos.
the class LoginServiceFacadeWebTier method updatePassword.
@Override
public boolean updatePassword(String username, String oldPassword, String newPassword) {
MifosUser appUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(appUser);
PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
boolean passwordIsAlreadyChanged = user.isPasswordChanged();
this.personnelService.changePassword(user, newPassword, true);
Date newExpirationDate = null;
if (user.getPasswordExpirationDate() != null) {
newExpirationDate = new LocalDateTime().plusDays(PasswordRules.getPasswordExpirationDatePrelongation()).toDateTime().toDate();
}
personnelService.changePasswordExpirationDate(user, newExpirationDate);
return passwordIsAlreadyChanged;
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class MeetingServiceFacadeWebTier method updateCustomerMeeting.
@Override
public void updateCustomerMeeting(MeetingDto meetingUpdateRequest, Integer customerId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = userContextFactory.create(user);
MeetingBO meeting = meetingFactory.create(meetingUpdateRequest);
meeting.updateDetails(userContext);
CustomerBO customer = this.customerDao.findCustomerById(customerId);
customer.updateDetails(userContext);
customerService.updateCustomerMeetingSchedule(meeting, customer);
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class PersonnelServiceFacadeWebTier method changeUserLocale.
@Override
public Short changeUserLocale(Short id, HttpServletRequest request) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (id != null) {
Short newLocaleId = id;
if (Localization.getInstance().getLocaleById(newLocaleId) != null) {
user.setPreferredLocaleId(newLocaleId);
try {
this.transactionHelper.startTransaction();
PersonnelBO p = this.personnelDao.findPersonnelById((short) user.getUserId());
p.setPreferredLocale(newLocaleId);
this.personnelDao.update(p);
this.transactionHelper.commitTransaction();
UserContext userContext = (UserContext) request.getSession().getAttribute(LoginConstants.USERCONTEXT);
userContext.setLocaleId(newLocaleId);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
ApplicationContextProvider.getBean(MessageLookup.class).updateLabelCache();
}
}
return user.getPreferredLocaleId();
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class PersonnelServiceFacadeWebTier method retrieveUserSettings.
@Override
public UserSettingsDto retrieveUserSettings() {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO personnel = this.personnelDao.findPersonnelById(userContext.getId());
String gender = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getGender());
String martialStatus = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getMaritalStatus());
String language = Localization.getInstance().getDisplayName(personnel.getPreferredLocale());
String sitePreference = SitePreferenceType.getSitePreference(personnel.getSitePreference()).name();
List<ValueListElement> genders = this.customerDao.retrieveGenders();
List<ValueListElement> martialStatuses = this.customerDao.retrieveMaritalStatuses();
List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
List<ValueListElement> sitePreferenceTypes = new ArrayList<ValueListElement>();
for (short i = 0; i < SitePreferenceType.values().length; i++) {
SitePreferenceType sitePreferenceType = SitePreferenceType.values()[i];
ValueListElement valueListElement = new BusinessActivityEntity(sitePreferenceType.getValue().intValue(), sitePreferenceType.name(), sitePreferenceType.name());
sitePreferenceTypes.add(valueListElement);
}
int age = DateUtils.DateDiffInYears(((Date) personnel.getPersonnelDetails().getDob()));
if (age < 0) {
age = 0;
}
return new UserSettingsDto(gender, martialStatus, language, age, sitePreference, genders, martialStatuses, languages, sitePreferenceTypes);
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class PersonnelServiceFacadeWebTier method updateUserSettings.
@Override
public void updateUserSettings(Short personnelId, String emailId, Name name, Integer maritalStatusValue, Integer genderValue, AddressDto address, Short preferredLocale, Short sitePreference) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO personnel = this.personnelDao.findPersonnelById(personnelId);
try {
personnel.updateDetails(userContext);
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(personnel);
Address theAddress = null;
if (address != null) {
theAddress = new Address(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
}
personnel.update(emailId, name, maritalStatusValue, genderValue, theAddress, preferredLocale, sitePreference);
if (preferredLocale != null && preferredLocale != 0) {
user.setPreferredLocaleId(preferredLocale);
}
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
Aggregations