Example #1
0
 public Urllib login() throws LoginException, BankException {
   try {
     LoginPackage lp = preLogin();
     response = urlopen.open(lp.getLoginTarget(), lp.getPostData());
     if (response.contains("Felaktigt anv")) {
       throw new LoginException(res.getText(R.string.invalid_username_password).toString());
     }
   } catch (ClientProtocolException e) {
     throw new BankException(e.getMessage());
   } catch (IOException e) {
     e.printStackTrace();
     throw new BankException(e.getMessage());
   }
   return urlopen;
 }
Example #2
0
  public SessionPackage getSessionPackage(Context context) {
    String preloader = "Error...";
    try {
      preloader = IOUtils.toString(context.getResources().openRawResource(R.raw.loading));
    } catch (NotFoundException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    try {
      LoginPackage lp = preLogin();
      if (lp == null) {
        throw new BankException(
            "No automatic login for this bank. preLogin() is not implemented or has failed.");
      }
      // TODO: Skip the form submission. Login using Bank.login(...) and transfer cookies to
      // webview. The user is now logged in
      //      and can me directed to any page.
      String html =
          String.format(
              preloader,
              "function go(){document.getElementById('submitform').submit(); }", // Javascript
                                                                                 // function
              Helpers.renderForm(lp.getLoginTarget(), lp.getPostData())
                  + "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>" // HTML
              );

      CookieStore cookies = urlopen.getHttpclient().getCookieStore();
      return new SessionPackage(html, cookies);
    } catch (ClientProtocolException e) {
      Log.e(TAG, e.getMessage());
    } catch (IOException e) {
      Log.e(TAG, e.getMessage());
    } catch (BankException e) {
      Log.e(TAG, e.getMessage());
    }
    String html =
        String.format(
            preloader,
            String.format(
                "function go(){window.location=\"%s\" }", this.URL), // Javascript function
            "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>" // HTML
            );
    return new SessionPackage(html, null);
  }
Example #3
0
  @Override
  public Urllib login() throws LoginException, BankException {
    try {
      LoginPackage lp = preLogin();
      String response = urlopen.open(lp.getLoginTarget(), lp.getPostData());

      Matcher matcher = reLoginError.matcher(response);
      if (matcher.find()) {
        throw new LoginException(Html.fromHtml(matcher.group(1)).toString().trim());
      }
    } catch (ClientProtocolException e) {
      throw new BankException(e.getMessage());
    } catch (IOException e) {
      throw new BankException(e.getMessage());
    }
    return urlopen;
  }