if (request.getSession().getAttribute(WebKeys.CMS_USER) == null) {
return new ActionForward("/dotCMS/login");
}
MyAccountForm form = (MyAccountForm) lf;
User user = (User) request.getSession().getAttribute(WebKeys.CMS_USER);
String userId = user.getUserId();
if (!Validator.validate(request, lf, mapping))
return mapping.findForward("myAccountPage");
// Saving Personal Information
HibernateUtil.startTransaction();
// User user = PublicUserFactory.getUserByEmail(userEmail);
UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(user,APILocator.getUserAPI().getSystemUser(), false);
user.setFirstName(form.getFirstName());
user.setLastName(form.getLastName());
userProxy.setOrganization(form.getOrganization());
userProxy.setWebsite(form.getWebsite());
userProxy.setMailSubscription(form.isMailSubscription());
userProxy.setPrefix(form.getPrefix());
userProxy.setSuffix(form.getSuffix());
userProxy.setTitle(form.getTitle());
// User Name and password
if (!form.getNewPassword().equals("")
|| !user.getEmailAddress().equals(form.getEmailAddress())
) {
if (!user.getPassword().equals(
PublicEncryptionFactory.digestString(form.getPassword()))) {
ActionErrors errors = new ActionErrors();
errors.add("password", new ActionMessage(
"current.usermanager.password.incorrect"));
saveMessages(request, errors);
return mapping.findForward("myAccountPage");
}
user.setPassword(PublicEncryptionFactory.digestString(form
.getNewPassword()));
user.setPasswordEncrypted(true);
user.setEmailAddress(form.getEmailAddress().trim().toLowerCase());
}
APILocator.getUserAPI().save(user,APILocator.getUserAPI().getSystemUser(),false);
HibernateUtil.saveOrUpdate(userProxy);
List<TagInode> tags = TagFactory.getTagInodeByInode(userProxy.getInode());
for (TagInode tag: tags) {
Tag tempTag = TagFactory.getTagByTagId(tag.getTagId());
TagFactory.deleteTagInode(tempTag.getTagName(), userProxy.getInode());
}
if(tags.size() > 0){
TagFactory.addTag(form.getTags(), userProxy.getUserId(), userProxy.getInode());
}
CategoryAPI categoryAPI = APILocator.getCategoryAPI();
List<Category> myUserCategories = categoryAPI.getChildren(userProxy, APILocator.getUserAPI().getSystemUser(), false);
for (Object object: myUserCategories) {
if ((object instanceof Category) && categoryAPI.canUseCategory((Category) object, APILocator.getUserAPI().getSystemUser(), false)) {
categoryAPI.removeChild(userProxy, (Category) object, APILocator.getUserAPI().getSystemUser(), false);
}
}
if (UtilMethods.isSet(form.getCategory())) {
Category category;
for (String categoryId: form.getCategory()) {
category = categoryAPI.find(categoryId, APILocator.getUserAPI().getSystemUser(), false);
if(InodeUtils.isSet(category.getInode())) {
categoryAPI.addChild(userProxy, category, APILocator.getUserAPI().getSystemUser(), false);
}
}