Example #1
0
  private void update() {

    if (!IConstants.CFG_NOTIFY_OLD_USERS) return;

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(User.class, PortalClassLoaderUtil.getClassLoader());
    dynamicQuery.add(RestrictionsFactoryUtil.eq("jobTitle", "mail-not-sent"));

    try {
      @SuppressWarnings("unchecked")
      List<User> users = UserLocalServiceUtil.dynamicQuery(dynamicQuery);

      int cnt = 0;

      for (User user : users) {
        // notifyUser thru email and SMS

        user.setJobTitle(StringPool.BLANK);
        user.setLastName(StringPool.BLANK);
        user = UserLocalServiceUtil.updateUser(user);
        cnt++;

        if (cnt == 200) break;
      }
    } catch (SystemException e) {
      e.printStackTrace();
    }
  }
  protected User addUser() throws Exception {
    long pk = nextLong();

    User user = _persistence.create(pk);

    user.setUuid(randomString());
    user.setCompanyId(nextLong());
    user.setCreateDate(nextDate());
    user.setModifiedDate(nextDate());
    user.setDefaultUser(randomBoolean());
    user.setContactId(nextLong());
    user.setPassword(randomString());
    user.setPasswordEncrypted(randomBoolean());
    user.setPasswordReset(randomBoolean());
    user.setPasswordModifiedDate(nextDate());
    user.setDigest(randomString());
    user.setReminderQueryQuestion(randomString());
    user.setReminderQueryAnswer(randomString());
    user.setGraceLoginCount(nextInt());
    user.setScreenName(randomString());
    user.setEmailAddress(randomString());
    user.setFacebookId(nextLong());
    user.setOpenId(randomString());
    user.setPortraitId(nextLong());
    user.setLanguageId(randomString());
    user.setTimeZoneId(randomString());
    user.setGreeting(randomString());
    user.setComments(randomString());
    user.setFirstName(randomString());
    user.setMiddleName(randomString());
    user.setLastName(randomString());
    user.setJobTitle(randomString());
    user.setLoginDate(nextDate());
    user.setLoginIP(randomString());
    user.setLastLoginDate(nextDate());
    user.setLastLoginIP(randomString());
    user.setLastFailedLoginDate(nextDate());
    user.setFailedLoginAttempts(nextInt());
    user.setLockout(randomBoolean());
    user.setLockoutDate(nextDate());
    user.setAgreedToTermsOfUse(randomBoolean());
    user.setStatus(nextInt());

    _persistence.update(user, false);

    return user;
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static User toModel(UserSoap soapModel) {
    User model = new UserImpl();

    model.setUuid(soapModel.getUuid());
    model.setUserId(soapModel.getUserId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setDefaultUser(soapModel.getDefaultUser());
    model.setContactId(soapModel.getContactId());
    model.setPassword(soapModel.getPassword());
    model.setPasswordEncrypted(soapModel.getPasswordEncrypted());
    model.setPasswordReset(soapModel.getPasswordReset());
    model.setPasswordModifiedDate(soapModel.getPasswordModifiedDate());
    model.setDigest(soapModel.getDigest());
    model.setReminderQueryQuestion(soapModel.getReminderQueryQuestion());
    model.setReminderQueryAnswer(soapModel.getReminderQueryAnswer());
    model.setGraceLoginCount(soapModel.getGraceLoginCount());
    model.setScreenName(soapModel.getScreenName());
    model.setEmailAddress(soapModel.getEmailAddress());
    model.setFacebookId(soapModel.getFacebookId());
    model.setOpenId(soapModel.getOpenId());
    model.setPortraitId(soapModel.getPortraitId());
    model.setLanguageId(soapModel.getLanguageId());
    model.setTimeZoneId(soapModel.getTimeZoneId());
    model.setGreeting(soapModel.getGreeting());
    model.setComments(soapModel.getComments());
    model.setFirstName(soapModel.getFirstName());
    model.setMiddleName(soapModel.getMiddleName());
    model.setLastName(soapModel.getLastName());
    model.setJobTitle(soapModel.getJobTitle());
    model.setLoginDate(soapModel.getLoginDate());
    model.setLoginIP(soapModel.getLoginIP());
    model.setLastLoginDate(soapModel.getLastLoginDate());
    model.setLastLoginIP(soapModel.getLastLoginIP());
    model.setLastFailedLoginDate(soapModel.getLastFailedLoginDate());
    model.setFailedLoginAttempts(soapModel.getFailedLoginAttempts());
    model.setLockout(soapModel.getLockout());
    model.setLockoutDate(soapModel.getLockoutDate());
    model.setAgreedToTermsOfUse(soapModel.getAgreedToTermsOfUse());
    model.setEmailAddressVerified(soapModel.getEmailAddressVerified());
    model.setStatus(soapModel.getStatus());

    return model;
  }
  protected User setGoogleCredentials(HttpSession session, long companyId, Credential credential)
      throws Exception {

    Userinfo userinfo = getUserInfo(credential);

    if (userinfo == null) {
      return null;
    }

    User user = null;

    String emailAddress = userinfo.getEmail();

    if ((user == null) && Validator.isNotNull(emailAddress)) {
      user = UserLocalServiceUtil.fetchUserByEmailAddress(companyId, emailAddress);

      if ((user != null) && (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {

        session.setAttribute("GOOGLE_USER_EMAIL_ADDRESS", emailAddress);
      }
    }

    if (user != null) {
      if (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE) {
        session.setAttribute("GOOGLE_INCOMPLETE_USER_ID", userinfo.getId());

        user.setEmailAddress(userinfo.getEmail());
        user.setFirstName(userinfo.getGivenName());
        user.setLastName(userinfo.getFamilyName());

        return user;
      }

      user = updateUser(user, userinfo);
    } else {
      user = addUser(session, companyId, userinfo);
    }

    if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) {
      updateCustomFields(user, userinfo, credential.getAccessToken(), credential.getRefreshToken());
    }

    return user;
  }
  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());
  }
Example #6
0
  private void insertOldUser(long companyId, long creatorUserId, String line) {

    String parts[] = line.split(StringPool.COMMA);

    boolean autoPassword = false;
    String password = parts[2];
    boolean autoScreenName = true;
    String screenName = StringPool.BLANK;
    String emailAddress = parts[1];
    long facebookId = 0l;
    String openId = StringPool.BLANK;
    String firstName = parts[3];
    String middleName = StringPool.BLANK;
    String lastName = StringPool.BLANK;
    int prefixId = 0;
    int suffixId = 0;
    boolean male = parts[6].equalsIgnoreCase("1");
    int birthdayMonth = 1;
    int birthdayDay = 1;
    int birthdayYear = 2000;
    String jobTitle = StringPool.BLANK;
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = false;

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy hh:mm");

    try {
      User user =
          UserLocalServiceUtil.addUser(
              creatorUserId,
              companyId,
              autoPassword,
              password,
              password,
              autoScreenName,
              screenName,
              emailAddress,
              facebookId,
              openId,
              Locale.US,
              firstName,
              middleName,
              lastName,
              prefixId,
              suffixId,
              male,
              birthdayMonth,
              birthdayDay,
              birthdayYear,
              jobTitle,
              groupIds,
              organizationIds,
              roleIds,
              userGroupIds,
              sendEmail,
              serviceContext);

      String createDate = parts[0];
      if (Validator.isNotNull(createDate)) {
        try {
          user.setCreateDate(dateFormat.parse(createDate));
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }

      String lastLoginDate = parts[5];
      if (Validator.isNotNull(lastLoginDate)) {
        try {
          user.setLastLoginDate(dateFormat.parse(lastLoginDate));
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }

      user.setLastName(parts[2]);
      user.setPasswordReset(false);
      user.setOpenId("no-invitation-check");
      user.setJobTitle("mail-not-sent");

      user = UserLocalServiceUtil.updateUser(user);

      _log.debug("User successfully created ==> " + user);

      String mobile = parts[4];

      if (Validator.isNotNull(mobile) && mobile.startsWith("091")) {
        String[] tokens = mobile.split(StringPool.DASH);
        if (tokens.length == 2 && tokens[1].length() == 10) {
          BridgeLocalServiceUtil.addPhone(
              user.getUserId(), User.class.getName(), user.getUserId(), tokens[1], "91", true);
        }
      }

    } catch (PortalException e) {
      _log.error(e.getMessage());
    } catch (SystemException e) {
      _log.error(e.getMessage());
    }
  }
Example #7
0
  private void createAccount(WebForm form, HttpServletRequest request) throws Exception {

    User user =
        APILocator.getUserAPI()
            .loadByUserByEmail(form.getEmail(), APILocator.getUserAPI().getSystemUser(), false);
    User defaultUser = APILocator.getUserAPI().getDefaultUser();
    Date today = new Date();

    if (user.isNew() || (!user.isNew() && user.getLastLoginDate() == null)) {

      // ### CREATE USER ###
      Company company = PublicCompanyFactory.getDefaultCompany();
      user.setEmailAddress(form.getEmail().trim().toLowerCase());
      user.setFirstName(form.getFirstName() == null ? "" : form.getFirstName());
      user.setMiddleName(form.getMiddleName() == null ? "" : form.getMiddleName());
      user.setLastName(form.getLastName() == null ? "" : form.getLastName());
      user.setNickName("");
      user.setCompanyId(company.getCompanyId());
      user.setPasswordEncrypted(true);
      user.setGreeting("Welcome, " + user.getFullName() + "!");

      // Set defaults values
      if (user.isNew()) {
        // if it's a new user we set random password
        String pass = PublicEncryptionFactory.getRandomPassword();
        user.setPassword(PublicEncryptionFactory.digestString(pass));
        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);
      // ### END CREATE USER ###

      // ### CREATE USER_PROXY ###
      UserProxy userProxy =
          com.dotmarketing.business.APILocator.getUserProxyAPI()
              .getUserProxy(user.getUserId(), APILocator.getUserAPI().getSystemUser(), false);
      userProxy.setPrefix("");
      userProxy.setTitle(form.getTitle());
      userProxy.setOrganization(form.getOrganization());
      userProxy.setUserId(user.getUserId());
      com.dotmarketing.business.APILocator.getUserProxyAPI()
          .saveUserProxy(userProxy, APILocator.getUserAPI().getSystemUser(), false);
      // ### END CRETE USER_PROXY ###

      // saving user inode on web form
      form.setUserInode(userProxy.getInode());
      if (UtilMethods.isSet(form.getFormType())) {
        HibernateUtil.saveOrUpdate(form);
      }

      ///// WE CAN DO THIS! BUT WE NEED TO ADD CATEGORIES TO WEBFORM AND ALSO CHANGE THE PROCESSES
      // THAT
      //// CREATE THE EXCEL DOWNLOAD FROM WEB FORMS. I DIDN'T ADD IT SO I COMMENTED THIS CODE FOR
      // NOW
      // get the old categories, wipe them out
      /*
      List<Category> categories = InodeFactory.getParentsOfClass(userProxy, Category.class);
      for (int i = 0; i < categories.size(); i++) {
      	categories.get(i).deleteChild(userProxy);
      }
       */
      // Save the new categories
      /*String[] arr = form.getCategories();
      if (arr != null) {
      	for (int i = 0; i < arr.length; i++) {
      		Category node = (Category) InodeFactory.getInode(arr[i], Category.class);
      		node.addChild(userProxy);
      	}
      }*/

      // ### CREATE ADDRESS ###
      try {
        List<Address> addresses = PublicAddressFactory.getAddressesByUserId(user.getUserId());
        Address address =
            (addresses.size() > 0 ? addresses.get(0) : PublicAddressFactory.getInstance());
        address.setStreet1(form.getAddress1() == null ? "" : form.getAddress1());
        address.setStreet2(form.getAddress2() == null ? "" : form.getAddress2());
        address.setCity(form.getCity() == null ? "" : form.getCity());
        address.setState(form.getState() == null ? "" : form.getState());
        address.setZip(form.getZip() == null ? "" : form.getZip());
        String phone = form.getPhone();
        address.setPhone(phone == null ? "" : phone);
        address.setUserId(user.getUserId());
        address.setCompanyId(company.getCompanyId());
        PublicAddressFactory.save(address);
      } catch (Exception ex) {
        Logger.error(this, ex.getMessage(), ex);
      }

      Role defaultRole =
          com.dotmarketing.business.APILocator.getRoleAPI()
              .loadRoleByKey(Config.getStringProperty("CMS_VIEWER_ROLE"));
      String roleId = defaultRole.getId();
      if (InodeUtils.isSet(roleId)) {
        com.dotmarketing.business.APILocator.getRoleAPI().addRoleToUser(roleId, user);
      }
    }
    // ### END CREATE ADDRESS ###

    // ### BUILD THE USER COMMENT ###
    addUserComments(user.getUserId(), form, request);
    // ### END BUILD THE USER COMMENT ###

    /* associate user with their clickstream request */
    if (Config.getBooleanProperty("ENABLE_CLICKSTREAM_TRACKING", false)) {
      ClickstreamFactory.setClickStreamUser(user.getUserId(), request);
    }
  }