private String _save(ActionForm form, ActionRequest req, ActionResponse res)
throws Exception {
User adminUser = _getUser(req);
UserManagerForm userForm = (UserManagerForm) form;
String userId = userForm.getUserID();
//Saving Personal Information
String companyId = com.dotmarketing.cms.factories.PublicCompanyFactory.getDefaultCompany().getCompanyId();
User user = null;
try {
user = APILocator.getUserAPI().loadUserById(userId,APILocator.getUserAPI().getSystemUser(),false);
} catch (Exception e) {
}
if (user == null)
user = retrieveMember(userId, userForm);
UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(user,APILocator.getUserAPI().getSystemUser(), false);
user.setFirstName(userForm.getFirstName());
if (userForm.getMiddleName() != null)
user.setMiddleName(userForm.getMiddleName());
user.setLastName(userForm.getLastName());
if (userForm.getDateOfBirthDate() != null)
user.setBirthday(userForm.getDateOfBirthDate());
if (userForm.getNickName() != null)
user.setNickName(userForm.getNickName());
if (userForm.getSex() != null)
user.setMale(userForm.getSex().equalsIgnoreCase("M") ? true : false);
if(UtilMethods.isSet(userForm.getChallengeQuestionId()) && UtilMethods.isInt(userForm.getChallengeQuestionId())){
userProxy.setChallengeQuestionId(userForm.getChallengeQuestionId());
}
if(UtilMethods.isSet(userForm.getChallengeQuestionAnswer())){
userProxy.setChallengeQuestionAnswer(userForm.getChallengeQuestionAnswer());
}
if (!userForm.getPrefix().equals("other"))
userProxy.setPrefix(userForm.getPrefix());
else
userProxy.setPrefix(userForm.getOtherPrefix());
userProxy.setSuffix(userForm.getSuffix());
userProxy.setTitle(userForm.getTitle());
userProxy.setCompany(companyId);
if (userForm.getSchool() != null)
userProxy.setSchool(userForm.getSchool());
if (0 < userForm.getGraduation_year())
userProxy.setGraduation_year(userForm.getGraduation_year());
// User Name and password
if (!UtilMethods.isSet(user.getEmailAddress()) || !user.getEmailAddress().equals(userForm.getEmailAddress()))
user.setEmailAddress(userForm.getEmailAddress().trim().toLowerCase());
if ((userForm.getNewPassword() != null) && (!userForm.getNewPassword().equals(""))) {
user.setPassword(PublicEncryptionFactory.digestString(userForm.getNewPassword()));
user.setPasswordEncrypted(true);
}
if (user.isNew() || userForm.getPassChanged().equals("true")) {
user.setPassword(PublicEncryptionFactory.digestString(userForm.getPassword()));
user.setPasswordEncrypted(true);
}
APILocator.getUserAPI().save(user,APILocator.getUserAPI().getSystemUser(),false);
_setRolePermission(userProxy, req);
if(!InodeUtils.isSet(userProxy.getInode()) ){
userProxy.setUserId(user.getUserId());
userProxy.setChallengeQuestionId("0");
com.dotmarketing.business.APILocator.getUserProxyAPI().saveUserProxy(userProxy,APILocator.getUserAPI().getSystemUser(), false);
} else {
com.dotmarketing.business.APILocator.getUserProxyAPI().saveUserProxy(userProxy,APILocator.getUserAPI().getSystemUser(), false);
}
//Saving User Address Information
Address address = retrieveAddress(user.getUserId());
address.setUserName(user.getFullName());
address.setClassName(user.getClass().getName());
address.setClassPK(user.getUserId());
address.setDescription(userForm.getDescription());
address.setStreet1(userForm.getStreet1());
address.setStreet2(userForm.getStreet2());
address.setCity(userForm.getCity());
address.setState(userForm.getState());
address.setZip(userForm.getZip());
address.setPhone(userForm.getPhone());
address.setFax(userForm.getFax());
if (userForm.getCountry() != null)
address.setCountry(userForm.getCountry());
address.setCell(userForm.getCell());
PublicAddressFactory.save(address);
// Add User Categories
if(userForm.getCategory() != null){
String[] categories = userForm.getCategory();
for(int i = 0 ; i < categories.length ;++i){
Category cat = categoryAPI.find(categories[i], adminUser, false);
categoryAPI.addChild(userProxy, cat, adminUser, false);
}
}