/**
   * Returns the user's full name.
   *
   * @return the user's full name
   */
  @AutoEscape
  @Override
  public String getFullName() {
    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    return fullNameGenerator.getFullName(getFirstName(), getMiddleName(), getLastName());
  }
示例#2
0
  protected String getUserName(long userId) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps =
          con.prepareStatement(
              "select firstName, middleName, lastName from User_ where " + "userId = ?");

      ps.setLong(1, userId);

      rs = ps.executeQuery();

      if (rs.next()) {
        String firstName = rs.getString("firstName");
        String middleName = rs.getString("middleName");
        String lastName = rs.getString("lastName");

        FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

        return fullNameGenerator.getFullName(firstName, middleName, lastName);
      }

      return StringPool.BLANK;
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
示例#3
0
  public void addUser(
      long companyId,
      long userId,
      String password,
      String firstName,
      String middleName,
      String lastName,
      String emailAddress) {

    try {
      String nickname = _getNickname(emailAddress);

      GUserManager gUserManager = GoogleAppsFactoryUtil.getGUserManager(companyId);

      gUserManager.addGUser(userId, password, firstName, lastName);

      GNicknameManager gNicknameManager = GoogleAppsFactoryUtil.getGNicknameManager(companyId);

      gNicknameManager.addGNickname(userId, nickname);

      GEmailSettingsManager gEmailSettingsManager =
          GoogleAppsFactoryUtil.getGEmailSettingsManager(companyId);

      FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

      gEmailSettingsManager.addSendAs(
          userId, fullNameGenerator.getFullName(firstName, middleName, lastName), emailAddress);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
示例#4
0
  @Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletURL portletURL,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String firstName = document.get("firstName");
    String middleName = document.get("middleName");
    String lastName = document.get("lastName");

    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    String title = fullNameGenerator.getFullName(firstName, middleName, lastName);

    String content = null;

    String userId = document.get(Field.USER_ID);

    portletURL.setParameter("struts_action", "/users_admin/edit_user");
    portletURL.setParameter("p_u_i_d", userId);

    return new Summary(title, content, portletURL);
  }
示例#5
0
  protected Object[] getDefaultUserArray(Connection con, long companyId) throws Exception {

    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      ps =
          con.prepareStatement(
              "select userId, firstName, middleName, lastName from User_"
                  + " where companyId = ? and defaultUser = ?");

      ps.setLong(1, companyId);
      ps.setBoolean(2, true);

      rs = ps.executeQuery();

      if (rs.next()) {
        long userId = rs.getLong("userId");
        String firstName = rs.getString("firstName");
        String middleName = rs.getString("middleName");
        String lastName = rs.getString("lastName");

        FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

        String userName = fullNameGenerator.getFullName(firstName, middleName, lastName);

        Timestamp createDate = new Timestamp(System.currentTimeMillis());

        return new Object[] {companyId, userId, userName, createDate, createDate};
      }

      return null;
    } finally {
      DataAccess.cleanUp(null, ps, rs);
    }
  }
  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());
  }