protected void redirectUpdateAccount( HttpServletRequest request, HttpServletResponse response, User user) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletURL portletURL = PortletURLFactoryUtil.create( request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("saveLastPath", Boolean.FALSE.toString()); portletURL.setParameter("struts_action", "/login/update_account"); PortletURL redirectURL = PortletURLFactoryUtil.create( request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); redirectURL.setParameter("struts_action", "/login/login_redirect"); redirectURL.setParameter("emailAddress", user.getEmailAddress()); redirectURL.setParameter("anonymousUser", Boolean.FALSE.toString()); redirectURL.setPortletMode(PortletMode.VIEW); redirectURL.setWindowState(LiferayWindowState.POP_UP); portletURL.setParameter("redirect", redirectURL.toString()); portletURL.setParameter("userId", String.valueOf(user.getUserId())); portletURL.setParameter("emailAddress", user.getEmailAddress()); portletURL.setParameter("firstName", user.getFirstName()); portletURL.setParameter("lastName", user.getLastName()); portletURL.setPortletMode(PortletMode.VIEW); portletURL.setWindowState(LiferayWindowState.POP_UP); response.sendRedirect(portletURL.toString()); }
public int compare(Object obj1, Object obj2) { User user1 = (User) obj1; User user2 = (User) obj2; int value = user1.getFirstName().compareTo(user2.getFirstName()); if (value == 0) { value = user1.getMiddleName().compareTo(user2.getMiddleName()); } if (value == 0) { value = user1.getLastName().compareTo(user2.getLastName()); } if (_asc) { return value; } else { return -value; } }
@Override protected Document doGetDocument(Object obj) throws Exception { User user = (User) obj; Document document = getBaseModelDocument(CLASS_NAME, user); long[] organizationIds = user.getOrganizationIds(); document.addKeyword(Field.COMPANY_ID, user.getCompanyId()); document.addKeyword(Field.GROUP_ID, user.getGroupIds()); document.addDate(Field.MODIFIED_DATE, user.getModifiedDate()); document.addKeyword(Field.SCOPE_GROUP_ID, user.getGroupIds()); document.addKeyword(Field.STATUS, user.getStatus()); document.addKeyword(Field.USER_ID, user.getUserId()); document.addKeyword(Field.USER_NAME, user.getFullName()); document.addKeyword( "ancestorOrganizationIds", getAncestorOrganizationIds(user.getOrganizationIds())); document.addText("emailAddress", user.getEmailAddress()); document.addText("firstName", user.getFirstName()); document.addText("fullName", user.getFullName()); document.addKeyword("groupIds", user.getGroupIds()); document.addText("jobTitle", user.getJobTitle()); document.addText("lastName", user.getLastName()); document.addText("middleName", user.getMiddleName()); document.addKeyword("organizationIds", organizationIds); document.addKeyword("organizationCount", String.valueOf(organizationIds.length)); document.addKeyword("roleIds", user.getRoleIds()); document.addText("screenName", user.getScreenName()); document.addKeyword("teamIds", user.getTeamIds()); document.addKeyword("userGroupIds", user.getUserGroupIds()); populateAddresses(document, user.getAddresses(), 0, 0); return document; }
public void testUpdateExisting() throws Exception { long pk = nextLong(); User newUser = _persistence.create(pk); newUser.setUuid(randomString()); newUser.setCompanyId(nextLong()); newUser.setCreateDate(nextDate()); newUser.setModifiedDate(nextDate()); newUser.setDefaultUser(randomBoolean()); newUser.setContactId(nextLong()); newUser.setPassword(randomString()); newUser.setPasswordEncrypted(randomBoolean()); newUser.setPasswordReset(randomBoolean()); newUser.setPasswordModifiedDate(nextDate()); newUser.setDigest(randomString()); newUser.setReminderQueryQuestion(randomString()); newUser.setReminderQueryAnswer(randomString()); newUser.setGraceLoginCount(nextInt()); newUser.setScreenName(randomString()); newUser.setEmailAddress(randomString()); newUser.setFacebookId(nextLong()); newUser.setOpenId(randomString()); newUser.setPortraitId(nextLong()); newUser.setLanguageId(randomString()); newUser.setTimeZoneId(randomString()); newUser.setGreeting(randomString()); newUser.setComments(randomString()); newUser.setFirstName(randomString()); newUser.setMiddleName(randomString()); newUser.setLastName(randomString()); newUser.setJobTitle(randomString()); newUser.setLoginDate(nextDate()); newUser.setLoginIP(randomString()); newUser.setLastLoginDate(nextDate()); newUser.setLastLoginIP(randomString()); newUser.setLastFailedLoginDate(nextDate()); newUser.setFailedLoginAttempts(nextInt()); newUser.setLockout(randomBoolean()); newUser.setLockoutDate(nextDate()); newUser.setAgreedToTermsOfUse(randomBoolean()); newUser.setStatus(nextInt()); _persistence.update(newUser, false); User existingUser = _persistence.findByPrimaryKey(newUser.getPrimaryKey()); assertEquals(existingUser.getUuid(), newUser.getUuid()); assertEquals(existingUser.getUserId(), newUser.getUserId()); assertEquals(existingUser.getCompanyId(), newUser.getCompanyId()); assertEquals( Time.getShortTimestamp(existingUser.getCreateDate()), Time.getShortTimestamp(newUser.getCreateDate())); assertEquals( Time.getShortTimestamp(existingUser.getModifiedDate()), Time.getShortTimestamp(newUser.getModifiedDate())); assertEquals(existingUser.getDefaultUser(), newUser.getDefaultUser()); assertEquals(existingUser.getContactId(), newUser.getContactId()); assertEquals(existingUser.getPassword(), newUser.getPassword()); assertEquals(existingUser.getPasswordEncrypted(), newUser.getPasswordEncrypted()); assertEquals(existingUser.getPasswordReset(), newUser.getPasswordReset()); assertEquals( Time.getShortTimestamp(existingUser.getPasswordModifiedDate()), Time.getShortTimestamp(newUser.getPasswordModifiedDate())); assertEquals(existingUser.getDigest(), newUser.getDigest()); assertEquals(existingUser.getReminderQueryQuestion(), newUser.getReminderQueryQuestion()); assertEquals(existingUser.getReminderQueryAnswer(), newUser.getReminderQueryAnswer()); assertEquals(existingUser.getGraceLoginCount(), newUser.getGraceLoginCount()); assertEquals(existingUser.getScreenName(), newUser.getScreenName()); assertEquals(existingUser.getEmailAddress(), newUser.getEmailAddress()); assertEquals(existingUser.getFacebookId(), newUser.getFacebookId()); assertEquals(existingUser.getOpenId(), newUser.getOpenId()); assertEquals(existingUser.getPortraitId(), newUser.getPortraitId()); assertEquals(existingUser.getLanguageId(), newUser.getLanguageId()); assertEquals(existingUser.getTimeZoneId(), newUser.getTimeZoneId()); assertEquals(existingUser.getGreeting(), newUser.getGreeting()); assertEquals(existingUser.getComments(), newUser.getComments()); assertEquals(existingUser.getFirstName(), newUser.getFirstName()); assertEquals(existingUser.getMiddleName(), newUser.getMiddleName()); assertEquals(existingUser.getLastName(), newUser.getLastName()); assertEquals(existingUser.getJobTitle(), newUser.getJobTitle()); assertEquals( Time.getShortTimestamp(existingUser.getLoginDate()), Time.getShortTimestamp(newUser.getLoginDate())); assertEquals(existingUser.getLoginIP(), newUser.getLoginIP()); assertEquals( Time.getShortTimestamp(existingUser.getLastLoginDate()), Time.getShortTimestamp(newUser.getLastLoginDate())); assertEquals(existingUser.getLastLoginIP(), newUser.getLastLoginIP()); assertEquals( Time.getShortTimestamp(existingUser.getLastFailedLoginDate()), Time.getShortTimestamp(newUser.getLastFailedLoginDate())); assertEquals(existingUser.getFailedLoginAttempts(), newUser.getFailedLoginAttempts()); assertEquals(existingUser.getLockout(), newUser.getLockout()); assertEquals( Time.getShortTimestamp(existingUser.getLockoutDate()), Time.getShortTimestamp(newUser.getLockoutDate())); assertEquals(existingUser.getAgreedToTermsOfUse(), newUser.getAgreedToTermsOfUse()); assertEquals(existingUser.getStatus(), newUser.getStatus()); }
protected User updateUser(User user, Userinfo userinfo) throws Exception { String emailAddress = userinfo.getEmail(); String firstName = userinfo.getGivenName(); String lastName = userinfo.getFamilyName(); boolean male = Validator.equals(userinfo.getGender(), "male"); if (emailAddress.equals(user.getEmailAddress()) && firstName.equals(user.getFirstName()) && lastName.equals(user.getLastName()) && (male == user.isMale())) { return user; } Contact contact = user.getContact(); Calendar birthdayCal = CalendarFactoryUtil.getCalendar(); birthdayCal.setTime(contact.getBirthday()); int birthdayMonth = birthdayCal.get(Calendar.MONTH); int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH); int birthdayYear = birthdayCal.get(Calendar.YEAR); long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; List<UserGroupRole> userGroupRoles = null; long[] userGroupIds = null; ServiceContext serviceContext = new ServiceContext(); if (!StringUtil.equalsIgnoreCase(emailAddress, user.getEmailAddress())) { UserLocalServiceUtil.updateEmailAddress( user.getUserId(), StringPool.BLANK, emailAddress, emailAddress); } UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), true); return UserLocalServiceUtil.updateUser( user.getUserId(), StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, false, user.getReminderQueryQuestion(), user.getReminderQueryAnswer(), user.getScreenName(), emailAddress, 0, user.getOpenId(), user.getLanguageId(), user.getTimeZoneId(), user.getGreeting(), user.getComments(), firstName, user.getMiddleName(), lastName, contact.getPrefixId(), contact.getSuffixId(), male, birthdayMonth, birthdayDay, birthdayYear, contact.getSmsSn(), contact.getAimSn(), contact.getFacebookSn(), contact.getIcqSn(), contact.getJabberSn(), contact.getMsnSn(), contact.getMySpaceSn(), contact.getSkypeSn(), contact.getTwitterSn(), contact.getYmSn(), contact.getJobTitle(), groupIds, organizationIds, roleIds, userGroupRoles, userGroupIds, serviceContext); }
@Override protected void doVerify() throws Exception { List<User> users = UserLocalServiceUtil.getNoContacts(); if (_log.isDebugEnabled()) { _log.debug("Processing " + users.size() + " users with no contacts"); } Date now = new Date(); for (User user : users) { if (_log.isDebugEnabled()) { _log.debug("Creating contact for user " + user.getUserId()); } long contactId = CounterLocalServiceUtil.increment(); Contact contact = ContactLocalServiceUtil.createContact(contactId); Company company = CompanyLocalServiceUtil.getCompanyById(user.getCompanyId()); contact.setCompanyId(user.getCompanyId()); contact.setUserId(user.getUserId()); contact.setUserName(StringPool.BLANK); contact.setCreateDate(now); contact.setModifiedDate(now); contact.setAccountId(company.getAccountId()); contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID); contact.setFirstName(user.getFirstName()); contact.setMiddleName(user.getMiddleName()); contact.setLastName(user.getLastName()); contact.setPrefixId(0); contact.setSuffixId(0); contact.setJobTitle(user.getJobTitle()); ContactLocalServiceUtil.updateContact(contact); user.setContactId(contactId); UserLocalServiceUtil.updateUser(user); } if (_log.isDebugEnabled()) { _log.debug("Contacts verified for users"); } users = UserLocalServiceUtil.getNoGroups(); if (_log.isDebugEnabled()) { _log.debug("Processing " + users.size() + " users with no groups"); } for (User user : users) { if (_log.isDebugEnabled()) { _log.debug("Creating group for user " + user.getUserId()); } GroupLocalServiceUtil.addGroup( user.getUserId(), User.class.getName(), user.getUserId(), null, null, 0, StringPool.SLASH + user.getScreenName(), false, true, null); } if (_log.isDebugEnabled()) { _log.debug("Groups verified for users"); } }