Ejemplo n.º 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();
    }
  }
Ejemplo n.º 2
0
  private static void _updateCompany(HttpServletRequest request) throws Exception {

    Company company = CompanyLocalServiceUtil.getCompanyById(PortalInstances.getDefaultCompanyId());

    Account account = company.getAccount();

    String currentName = account.getName();

    String newName = ParamUtil.getString(request, "companyName", PropsValues.COMPANY_DEFAULT_NAME);

    if (!currentName.equals(newName)) {
      account.setName(newName);

      AccountLocalServiceUtil.updateAccount(account);
    }

    String languageId =
        ParamUtil.getString(request, "companyLocale", PropsValues.COMPANY_DEFAULT_LOCALE);

    User defaultUser = company.getDefaultUser();

    defaultUser.setLanguageId(languageId);

    UserLocalServiceUtil.updateUser(defaultUser);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    themeDisplay.setCompany(company);
  }
Ejemplo n.º 3
0
 /*
  * NOTE FOR DEVELOPERS:
  *
  * Never modify or reference this class directly. All methods that expect a user model instance should use the {@link User} interface instead.
  */
 public void persist() throws SystemException {
   if (this.isNew()) {
     UserLocalServiceUtil.addUser(this);
   } else {
     UserLocalServiceUtil.updateUser(this);
   }
 }
Ejemplo n.º 4
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());
    }
  }
Ejemplo n.º 5
0
  private static void _updateAdminUser(
      HttpServletRequest request, UnicodeProperties unicodeProperties) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = CompanyLocalServiceUtil.getCompanyById(themeDisplay.getCompanyId());

    String emailAddress =
        ParamUtil.getString(
            request,
            "adminEmailAddress",
            PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + StringPool.AT + company.getMx());

    PropsValues.ADMIN_EMAIL_FROM_ADDRESS = emailAddress;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_ADDRESS, emailAddress);

    ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

    String screenName =
        GetterUtil.getString(PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX, "test");

    try {
      screenName = screenNameGenerator.generate(0, 0, emailAddress);
    } catch (Exception e) {
    }

    String firstName =
        ParamUtil.getString(request, "adminFirstName", PropsValues.DEFAULT_ADMIN_FIRST_NAME);
    String lastName =
        ParamUtil.getString(request, "adminLastName", PropsValues.DEFAULT_ADMIN_LAST_NAME);

    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    String fullName = fullNameGenerator.getFullName(firstName, null, lastName);

    PropsValues.ADMIN_EMAIL_FROM_NAME = fullName;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_NAME, fullName);

    User user = null;

    try {
      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String greeting =
          LanguageUtil.format(
              themeDisplay.getLocale(), "welcome-x", StringPool.SPACE + fullName, false);

      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);

      user =
          UserLocalServiceUtil.updateUser(
              user.getUserId(),
              StringPool.BLANK,
              StringPool.BLANK,
              StringPool.BLANK,
              false,
              user.getReminderQueryQuestion(),
              user.getReminderQueryAnswer(),
              screenName,
              emailAddress,
              user.getFacebookId(),
              user.getOpenId(),
              themeDisplay.getLanguageId(),
              user.getTimeZoneId(),
              greeting,
              user.getComments(),
              firstName,
              user.getMiddleName(),
              lastName,
              contact.getPrefixId(),
              contact.getSuffixId(),
              contact.isMale(),
              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(),
              null,
              null,
              null,
              null,
              null,
              new ServiceContext());
    } catch (NoSuchUserException nsue) {
      UserLocalServiceUtil.addDefaultAdminUser(
          themeDisplay.getCompanyId(),
          screenName,
          emailAddress,
          themeDisplay.getLocale(),
          firstName,
          StringPool.BLANK,
          lastName);

      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String defaultAdminEmailAddress =
          PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + "@" + PropsValues.COMPANY_DEFAULT_WEB_ID;

      if (!emailAddress.equals(defaultAdminEmailAddress)) {
        User testUser =
            UserLocalServiceUtil.fetchUserByEmailAddress(
                themeDisplay.getCompanyId(), defaultAdminEmailAddress);

        if (testUser != null) {
          UserLocalServiceUtil.updateStatus(
              testUser.getUserId(), WorkflowConstants.STATUS_INACTIVE);
        }
      }
    }

    user = UserLocalServiceUtil.updatePasswordReset(user.getUserId(), true);

    HttpSession session = request.getSession();

    session.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
    session.setAttribute(WebKeys.SETUP_WIZARD_PASSWORD_UPDATED, true);
    session.setAttribute(WebKeys.USER_ID, user.getUserId());
  }
  protected User updateUser(
      long companyId, LDAPUser ldapUser, User user, String password, String modifiedDate)
      throws Exception {

    Date ldapUserModifiedDate = null;

    try {
      if (Validator.isNull(modifiedDate)) {
        if (_log.isInfoEnabled()) {
          _log.info("LDAP entry never modified, skipping user " + user.getEmailAddress());
        }

        return user;
      } else {
        ldapUserModifiedDate = LDAPUtil.parseDate(modifiedDate);
      }

      if (ldapUserModifiedDate.equals(user.getModifiedDate()) && ldapUser.isAutoPassword()) {

        if (_log.isDebugEnabled()) {
          _log.debug("User is already synchronized, skipping user " + user.getEmailAddress());
        }

        return user;
      }
    } catch (ParseException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug("Unable to parse LDAP modify timestamp " + modifiedDate, pe);
      }
    }

    boolean passwordReset = ldapUser.isPasswordReset();

    if (PrefsPropsUtil.getBoolean(
        companyId, PropsKeys.LDAP_EXPORT_ENABLED, PropsValues.LDAP_EXPORT_ENABLED)) {

      passwordReset = user.isPasswordReset();
    }

    if (!PropsValues.LDAP_IMPORT_USER_PASSWORD_ENABLED) {
      password = PropsValues.LDAP_IMPORT_USER_PASSWORD_DEFAULT;

      if (password.equalsIgnoreCase(_USER_PASSWORD_SCREEN_NAME)) {
        password = ldapUser.getScreenName();
      }
    }

    if (Validator.isNull(ldapUser.getScreenName())) {
      ldapUser.setAutoScreenName(true);
    }

    if (ldapUser.isAutoScreenName()) {
      ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

      ldapUser.setScreenName(
          screenNameGenerator.generate(companyId, user.getUserId(), ldapUser.getEmailAddress()));
    }

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(user.getContact().getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    if (ldapUser.isUpdatePassword()) {
      UserLocalServiceUtil.updatePassword(
          user.getUserId(), password, password, passwordReset, true);
    }

    Contact contact = user.getContact();

    Set<String> ldapIgnoreAttributes = SetUtil.fromArray(PropsValues.LDAP_USER_IGNORE_ATTRIBUTES);

    for (String attribute : ldapIgnoreAttributes) {
      Object value = BeanPropertiesUtil.getObjectSilent(user, attribute);

      if (value == null) {
        value = BeanPropertiesUtil.getObjectSilent(contact, attribute);
      }

      if (value != null) {
        BeanPropertiesUtil.setProperty(ldapUser, attribute, value);
      }
    }

    updateLDAPUser(ldapUser.getUser(), ldapUser.getContact(), user);

    user =
        UserLocalServiceUtil.updateUser(
            user.getUserId(),
            password,
            StringPool.BLANK,
            StringPool.BLANK,
            passwordReset,
            ldapUser.getReminderQueryQuestion(),
            ldapUser.getReminderQueryAnswer(),
            ldapUser.getScreenName(),
            ldapUser.getEmailAddress(),
            ldapUser.getFacebookId(),
            ldapUser.getOpenId(),
            ldapUser.getLanguageId(),
            ldapUser.getTimeZoneId(),
            ldapUser.getGreeting(),
            ldapUser.getComments(),
            ldapUser.getFirstName(),
            ldapUser.getMiddleName(),
            ldapUser.getLastName(),
            ldapUser.getPrefixId(),
            ldapUser.getSuffixId(),
            ldapUser.isMale(),
            birthdayMonth,
            birthdayDay,
            birthdayYear,
            ldapUser.getSmsSn(),
            ldapUser.getAimSn(),
            ldapUser.getFacebookSn(),
            ldapUser.getIcqSn(),
            ldapUser.getJabberSn(),
            ldapUser.getMsnSn(),
            ldapUser.getMySpaceSn(),
            ldapUser.getSkypeSn(),
            ldapUser.getTwitterSn(),
            ldapUser.getYmSn(),
            ldapUser.getJobTitle(),
            ldapUser.getGroupIds(),
            ldapUser.getOrganizationIds(),
            ldapUser.getRoleIds(),
            ldapUser.getUserGroupRoles(),
            ldapUser.getUserGroupIds(),
            ldapUser.getServiceContext());

    if (ldapUserModifiedDate != null) {
      user = UserLocalServiceUtil.updateModifiedDate(user.getUserId(), ldapUserModifiedDate);
    }

    if (ldapUser.isUpdatePortrait()) {
      byte[] portraitBytes = ldapUser.getPortraitBytes();

      if ((portraitBytes != null) && (portraitBytes.length > 0)) {
        UserLocalServiceUtil.updatePortrait(user.getUserId(), portraitBytes);
      } else {
        UserLocalServiceUtil.deletePortrait(user.getUserId());
      }
    }

    return user;
  }
  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");
    }
  }