}
@SuppressWarnings("unchecked")
private void createAccount(CreateAccountForm form, HttpServletRequest request, HttpServletResponse response) throws NoSuchUserException, DotDataException, DotSecurityException {
CreateAccountForm createAccountForm = (CreateAccountForm) form;
User user = new User();
UserAPI uAPI = APILocator.getUserAPI();
try {
user = uAPI.createUser(null, form.getEmailAddress());
//user = APILocator.getUserAPI().loadByUserByEmail(form.getEmailAddress(), APILocator.getUserAPI().getSystemUser(), false);
} catch (Exception e1) {
Logger.warn(this, e1.toString());
}
User defaultUser = APILocator.getUserAPI().getDefaultUser();
Date today = new Date();
//### CREATE USER ###
Company company = PublicCompanyFactory.getDefaultCompany();
user.setEmailAddress(createAccountForm.getEmailAddress().trim().toLowerCase());
user.setFirstName(createAccountForm.getFirstName() == null ? "" : form.getFirstName());
user.setLastName(createAccountForm.getLastName() == null ? "" : form.getLastName());
user.setNickName("");
user.setMiddleName("");
user.setCompanyId(company.getCompanyId());
user.setLastLoginIP(request.getRemoteAddr());
user.setLastLoginDate(today);
user.setLoginIP(request.getRemoteAddr());
user.setLoginDate(today);
user.setPasswordEncrypted(true);
user.setPassword(PublicEncryptionFactory.digestString(form.getPassword1()));
user.setComments(form.getComments());
user.setGreeting("Welcome, " + user.getFullName() + "!");
//Set defaults values
if(user.isNew())
{
user.setLanguageId(defaultUser.getLanguageId());
user.setTimeZoneId(defaultUser.getTimeZoneId());
user.setSkinId(defaultUser.getSkinId());
user.setDottedSkins(defaultUser.isDottedSkins());
user.setRoundedSkins(defaultUser.isRoundedSkins());
user.setResolution(defaultUser.getResolution());
user.setRefreshRate(defaultUser.getRefreshRate());
user.setLayoutIds("");
user.setActive(true);
user.setCreateDate(today);
}
APILocator.getUserAPI().save(user,APILocator.getUserAPI().getSystemUser(),false);
//### CREATE USER_PROXY ###
UserProxy userProxy = com.dotmarketing.business.APILocator.getUserProxyAPI().getUserProxy(user.getUserId(),APILocator.getUserAPI().getSystemUser(), false);
userProxy.setUserId(user.getUserId());
userProxy.setPrefix(createAccountForm.getPrefix());
userProxy.setSuffix(createAccountForm.getSuffix());
userProxy.setTitle(createAccountForm.getTitle());
userProxy.setSchool(createAccountForm.getSchool());
userProxy.setGraduationYear(createAccountForm.getGraduationYear());
userProxy.setOrganization(createAccountForm.getOrganization());
userProxy.setCompany(createAccountForm.getOrganization());
userProxy.setWebsite(createAccountForm.getWebsite());
userProxy.setHowHeard(createAccountForm.getHowHeard());
userProxy.setVar1(createAccountForm.getVar1());
userProxy.setVar2(createAccountForm.getVar2());
userProxy.setVar3(createAccountForm.getVar3());
userProxy.setVar4(createAccountForm.getVar4());
userProxy.setVar5(createAccountForm.getVar5());
userProxy.setVar6(createAccountForm.getVar6());
userProxy.setVar7(createAccountForm.getVar7());
userProxy.setVar8(createAccountForm.getVar8());
userProxy.setVar9(createAccountForm.getVar9());
userProxy.setVar10(createAccountForm.getVar10());
userProxy.setVar11(createAccountForm.getVar11());
userProxy.setVar12(createAccountForm.getVar12());
userProxy.setVar13(createAccountForm.getVar13());
userProxy.setVar14(createAccountForm.getVar14());
userProxy.setVar15(createAccountForm.getVar15());
userProxy.setVar16(createAccountForm.getVar16());
userProxy.setVar17(createAccountForm.getVar17());
userProxy.setVar18(createAccountForm.getVar18());
userProxy.setVar19(createAccountForm.getVar19());
userProxy.setVar20(createAccountForm.getVar20());
userProxy.setVar21(createAccountForm.getVar21());
userProxy.setVar22(createAccountForm.getVar22());
userProxy.setVar23(createAccountForm.getVar23());
userProxy.setVar24(createAccountForm.getVar24());
userProxy.setVar25(createAccountForm.getVar25());
if (UtilMethods.isSet(createAccountForm.getDescription()) ||
UtilMethods.isSet(createAccountForm.getStreet1()) ||
UtilMethods.isSet(createAccountForm.getStreet2()) ||
UtilMethods.isSet(createAccountForm.getCity()) ||
UtilMethods.isSet(createAccountForm.getState()) ||
UtilMethods.isSet(createAccountForm.getZip()) ||
UtilMethods.isSet(createAccountForm.getCountry()) ||
UtilMethods.isSet(createAccountForm.getPhone()) ||
UtilMethods.isSet(createAccountForm.getFax()) ||
UtilMethods.isSet(createAccountForm.getCell())) {
try {
List<Address> addresses = PublicAddressFactory.getAddressesByUserId(user.getUserId());
Address address = (addresses.size() > 0 ? addresses.get(0) : PublicAddressFactory.getInstance());
address.setDescription(createAccountForm.getDescription() == null ? "" : createAccountForm.getDescription());
address.setStreet1(createAccountForm.getStreet1() == null ? "" : createAccountForm.getStreet1());
address.setStreet2(createAccountForm.getStreet2() == null ? "" : createAccountForm.getStreet2());
address.setCity(createAccountForm.getCity() == null ? "" : createAccountForm.getCity());
address.setState(createAccountForm.getState() == null ? "" : createAccountForm.getState());
address.setZip(createAccountForm.getZip() == null ? "" : createAccountForm.getZip());
address.setCountry(createAccountForm.getCountry() == null ? "" : createAccountForm.getCountry());
address.setPhone(createAccountForm.getPhone() == null ? "" : createAccountForm.getPhone());
address.setFax(createAccountForm.getFax() == null ? "" : createAccountForm.getFax());
address.setCell( createAccountForm.getCell() == null ? "" : createAccountForm.getCell());
address.setUserId(user.getUserId());
address.setCompanyId(company.getCompanyId());
PublicAddressFactory.save(address);
} catch (Exception e) {
Logger.warn(this, e.toString());
}
}
userProxy.setMailSubscription(createAccountForm.isMailSubscription());
com.dotmarketing.business.APILocator.getUserProxyAPI().saveUserProxy(userProxy,APILocator.getUserAPI().getSystemUser(), false);
//### END CRETE USER_PROXY ###
String[] arr = form.getCategories();