Example #1
-1
  public static String sendNewPassword(
      final UserInfoBean userInfoBean,
      final PwmApplication pwmApplication,
      final MacroMachine macroMachine,
      final PasswordData newPassword,
      final Locale userLocale,
      final MessageSendMethod messageSendMethod)
      throws PwmOperationalException, PwmUnrecoverableException {
    final String emailAddress = userInfoBean.getUserEmailAddress();
    final String smsNumber = userInfoBean.getUserSmsNumber();
    String returnToAddress = emailAddress;

    ErrorInformation error = null;
    switch (messageSendMethod) {
      case BOTH:
        // Send both email and SMS, success if one of both succeeds
        final ErrorInformation err1 =
            sendNewPasswordEmail(
                userInfoBean, pwmApplication, macroMachine, newPassword, emailAddress, userLocale);
        final ErrorInformation err2 =
            sendNewPasswordSms(
                userInfoBean, pwmApplication, macroMachine, newPassword, smsNumber, userLocale);
        if (err1 != null) {
          error = err1;
          returnToAddress = smsNumber;
        } else if (err2 != null) {
          error = err2;
        }
        break;
      case EMAILFIRST:
        // Send email first, try SMS if email is not available
        error =
            sendNewPasswordEmail(
                userInfoBean, pwmApplication, macroMachine, newPassword, emailAddress, userLocale);
        if (error != null) {
          error =
              sendNewPasswordSms(
                  userInfoBean, pwmApplication, macroMachine, newPassword, smsNumber, userLocale);
          returnToAddress = smsNumber;
        }
        break;
      case SMSFIRST:
        // Send SMS first, try email if SMS is not available
        error =
            sendNewPasswordSms(
                userInfoBean, pwmApplication, macroMachine, newPassword, smsNumber, userLocale);
        if (error != null) {
          error =
              sendNewPasswordEmail(
                  userInfoBean,
                  pwmApplication,
                  macroMachine,
                  newPassword,
                  emailAddress,
                  userLocale);
        } else {
          returnToAddress = smsNumber;
        }
        break;
      case SMSONLY:
        // Only try SMS
        error =
            sendNewPasswordSms(
                userInfoBean, pwmApplication, macroMachine, newPassword, smsNumber, userLocale);
        returnToAddress = smsNumber;
        break;
      case EMAILONLY:
      default:
        // Only try email
        error =
            sendNewPasswordEmail(
                userInfoBean, pwmApplication, macroMachine, newPassword, emailAddress, userLocale);
        break;
    }
    if (error != null) {
      throw new PwmOperationalException(error);
    }
    return returnToAddress;
  }