public boolean validateUserData(ActionRequest request) {
    if (isNullOrEmpty(getGivenname())) {
      SessionMessages.add(request, "request_processed", "First name cannot be empty");
      return false;
    }
    if (isNullOrEmpty(getLastname())) {
      SessionMessages.add(request, "request_processed", "Last name cannot be empty");
      return false;
    }
    if (!Validator.isEmailAddress(getEmail())) {
      SessionMessages.add(request, "request_processed", "Email is not valid");
      return false;
    }
    if (isNullOrEmpty(getDepartment())) {
      SessionMessages.add(request, "request_processed", "Department cannot be empty");
      return false;
    }
    if (isNullOrEmpty(getExternalid())) {
      SessionMessages.add(request, "request_processed", "External ID cannot be empty");
      return false;
    }
    if (isNullOrEmpty(password)) {
      SessionMessages.add(request, "request_processed", "Password cannot be empty");
      return false;
    }
    try {
      SW360Assert.assertEquals(password, password2);
    } catch (SW360Exception e) {
      SessionMessages.add(request, "request_processed", "Passwords don't match");
      return false;
    }

    return true;
  }
Beispiel #2
0
  public InternetAddress[] parseAddresses(String addresses) throws PortalException {

    InternetAddress[] internetAddresses = new InternetAddress[0];

    try {
      internetAddresses = InternetAddress.parse(addresses, true);

      for (int i = 0; i < internetAddresses.length; i++) {
        InternetAddress internetAddress = internetAddresses[i];

        if (!Validator.isEmailAddress(internetAddress.getAddress())) {
          StringBundler sb = new StringBundler(4);

          sb.append(internetAddress.getPersonal());
          sb.append(StringPool.LESS_THAN);
          sb.append(internetAddress.getAddress());
          sb.append(StringPool.GREATER_THAN);

          throw new MailException(MailException.MESSAGE_INVALID_ADDRESS, sb.toString());
        }
      }
    } catch (AddressException ae) {
      throw new MailException(MailException.MESSAGE_INVALID_ADDRESS, ae, addresses);
    }

    return internetAddresses;
  }
  protected void validate(long entryId, long userId, String fullName, String emailAddress)
      throws PortalException {

    if (Validator.isNull(fullName)) {
      throw new ContactFullNameException();
    }

    if (Validator.isNull(emailAddress)) {
      throw new RequiredEntryEmailAddressException();
    }

    if (!Validator.isEmailAddress(emailAddress)) {
      throw new EntryEmailAddressException();
    }

    if (entryId > 0) {
      Entry entry = entryPersistence.findByPrimaryKey(entryId);

      if (!StringUtil.equalsIgnoreCase(emailAddress, entry.getEmailAddress())) {

        validateEmailAddress(userId, emailAddress);
      }
    } else {
      validateEmailAddress(userId, emailAddress);
    }
  }
  protected void validate(
      long companyId,
      boolean autoPassword,
      String password1,
      String password2,
      boolean autoScreenName,
      String screenName,
      String emailAddress,
      String firstName,
      String lastName,
      long organizationId,
      long locationId)
      throws PortalException, SystemException {

    if (!autoScreenName) {
      validateScreenName(companyId, screenName);
    }

    if (!autoPassword) {
      PasswordPolicy passwordPolicy =
          PasswordPolicyLocalServiceUtil.getDefaultPasswordPolicy(companyId);

      PwdToolkitUtil.validate(companyId, 0, password1, password2, passwordPolicy);
    }

    if (!Validator.isEmailAddress(emailAddress)) {
      throw new UserEmailAddressException();
    } else {
      // As per caGrid requirements portal can have duplicate email address for a particular company
      // Id.
      /*try {
      	User user = UserUtil.findByC_EA(companyId, emailAddress);

      	if (user != null) {
      		throw new DuplicateUserEmailAddressException();
      	}
      } catch (NoSuchUserException nsue) {
      }*/

      String[] reservedEmailAddresses =
          PrefsPropsUtil.getStringArray(companyId, PropsUtil.ADMIN_RESERVED_EMAIL_ADDRESSES);

      for (int i = 0; i < reservedEmailAddresses.length; i++) {
        if (emailAddress.equalsIgnoreCase(reservedEmailAddresses[i])) {
          throw new ReservedUserEmailAddressException();
        }
      }
    }

    if (Validator.isNull(firstName)) {
      throw new ContactFirstNameException();
    } else if (Validator.isNull(lastName)) {
      throw new ContactLastNameException();
    }
  }
Beispiel #5
0
  public boolean validate(long companyId, String screenName) {
    if (Validator.isEmailAddress(screenName)
        || screenName.equalsIgnoreCase(CYRUS)
        || screenName.equalsIgnoreCase(POSTFIX)
        || (screenName.indexOf(CharPool.SLASH) != -1)
        || (screenName.indexOf(CharPool.UNDERLINE) != -1)) {

      return false;
    } else {
      return true;
    }
  }
  protected void updateEmailFrom(ActionRequest actionRequest, ShoppingPreferences preferences)
      throws Exception {

    String emailFromName = ParamUtil.getString(actionRequest, "emailFromName");
    String emailFromAddress = ParamUtil.getString(actionRequest, "emailFromAddress");

    if (Validator.isNull(emailFromName)) {
      SessionErrors.add(actionRequest, "emailFromName");
    } else if (!Validator.isEmailAddress(emailFromAddress)) {
      SessionErrors.add(actionRequest, "emailFromAddress");
    } else {
      preferences.setEmailFromName(emailFromName);
      preferences.setEmailFromAddress(emailFromAddress);
    }
  }
  public static boolean validateRegistration(Contact contact, List errors) throws Exception {

    boolean valid = true;

    _log.debug("contact.getFullname():" + contact.getFullname());
    _log.debug("contact.getEmail():" + contact.getEmail());
    _log.debug("contact.getPhone():" + contact.getPhone());
    _log.debug("contact.getSubject():" + contact.getSubject());
    _log.debug("contact.getCommunity():" + contact.getCommunity());

    if (Validator.isNull(contact.getFullname())) {
      errors.add("fullname-required");
      valid = false;
    }

    if (Validator.isNull(contact.getEmail())) {
      errors.add("email-required");
      valid = false;
    } else if (!Validator.isEmailAddress(contact.getEmail())) {
      errors.add("email-invalid");
      valid = false;
    }

    /*if (Validator.isNull(contact.getPhone())) {
        errors.add("phone-required");
        valid = false;
    }*/

    if (Validator.isNotNull(contact.getPhone())) {
      if (!Validator.isPhoneNumber(contact.getPhone())) {
        errors.add("phone-invalid");
        valid = false;
      }
    }

    /*
    if (Validator.isNull(contact.getSubject())) {
        errors.add("subject-required");
        valid = false;
    }
    */

    _log.debug("valid:" + valid);

    return valid;
  }
  public void addMemberRequests(
      long userId,
      long groupId,
      String[] emailAddresses,
      long invitedRoleId,
      long invitedTeamId,
      ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    for (String emailAddress : emailAddresses) {
      if (!Validator.isEmailAddress(emailAddress)) {
        continue;
      }

      addMemberRequest(
          userId, groupId, 0, emailAddress, invitedRoleId, invitedTeamId, themeDisplay);
    }
  }
  protected void validateFields(ActionRequest actionRequest) throws Exception {

    Locale defaultLocale = LocaleUtil.getDefault();
    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    boolean sendAsEmail = GetterUtil.getBoolean(getParameter(actionRequest, "sendAsEmail"));
    String subject = getParameter(actionRequest, "subject");

    boolean saveToDatabase = GetterUtil.getBoolean(getParameter(actionRequest, "saveToDatabase"));

    boolean saveToFile = GetterUtil.getBoolean(getParameter(actionRequest, "saveToFile"));

    if (!sendAsEmail && !saveToDatabase && !saveToFile) {
      SessionErrors.add(actionRequest, "handlingRequired");
    }

    if (sendAsEmail) {
      if (Validator.isNull(subject)) {
        SessionErrors.add(actionRequest, "subjectRequired");
      }

      String[] emailAdresses = WebFormUtil.split(getParameter(actionRequest, "emailAddress"));

      if (emailAdresses.length == 0) {
        SessionErrors.add(actionRequest, "emailAddressRequired");
      }

      for (String emailAdress : emailAdresses) {
        emailAdress = emailAdress.trim();

        if (!Validator.isEmailAddress(emailAdress)) {
          SessionErrors.add(actionRequest, "emailAddressInvalid");
        }
      }
    }

    if (saveToFile) {
      String fileName = getParameter(actionRequest, "fileName");

      // Check if server can create a file as specified

      try {
        FileOutputStream fileOutputStream = new FileOutputStream(fileName, true);

        fileOutputStream.close();
      } catch (SecurityException se) {
        SessionErrors.add(actionRequest, "fileNameInvalid");
      } catch (FileNotFoundException fnfe) {
        SessionErrors.add(actionRequest, "fileNameInvalid");
      }
    }

    if (saveToDatabase) {
      int i = 1;

      String languageId = LocaleUtil.toLanguageId(actionRequest.getLocale());

      String fieldLabel = ParamUtil.getString(actionRequest, "fieldLabel" + i + "_" + languageId);

      while ((i == 1) || Validator.isNotNull(fieldLabel)) {
        if (fieldLabel.length() > 75) {
          SessionErrors.add(actionRequest, "fieldSizeInvalid" + i);
        }

        i++;

        fieldLabel = ParamUtil.getString(actionRequest, "fieldLabel" + i + "_" + languageId);
      }
    }

    if (!validateUniqueFieldNames(actionRequest)) {
      SessionErrors.add(actionRequest, DuplicateColumnNameException.class.getName());
    }
  }
  protected void login(
      ThemeDisplay themeDisplay,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      PortletPreferences preferences)
      throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    String authType = preferences.getValue("authType", null);

    // cusotm code =============
    try {
      User tmp = null;
      UserEntry userEntryTmp = null;
      if (Validator.isEmailAddress(login)) {
        tmp = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(request), login);
        login = String.valueOf(tmp.getUserId());
        System.out.println("email:" + login);
      } else if (Validator.isNumber(login)) {
        // is mobile number
        //				UserEntryLocalServiceUtil.get
        userEntryTmp = UserEntryLocalServiceUtil.findByMobilePhone(login);
        login = String.valueOf(userEntryTmp.getUserId());
        System.out.println("mobile number:" + login);
      } else {
        // userEntryTmp = UserEntryLocalServiceUtil.findByUserName(login);
        tmp = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getCompanyId(request), login);
        login = String.valueOf(tmp.getUserId());
        System.out.println("userName:"******"/portal/protected");
    } else {
      String redirect = ParamUtil.getString(actionRequest, "redirect");

      if (Validator.isNotNull(redirect)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (!redirect.startsWith(Http.HTTP)) {
          redirect = getCompleteRedirectURL(request, redirect);
        }

        actionResponse.sendRedirect(redirect);
      } else {
        boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

        if (doActionAfterLogin) {
          return;
        } else {
          actionResponse.sendRedirect(themeDisplay.getPathMain());
        }
      }
    }
  }