@Override protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException { Urllib weblogin = new Urllib(false, true); String response = weblogin.open("https://mobil.lansforsakringar.se/lf-mobile/pages/login.faces"); Matcher matcher = reViewState.matcher(response); if (!matcher.find()) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " ViewState."); } String viewState = matcher.group(1); matcher = reLoginToken.matcher(response); if (!matcher.find()) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " LoginToken."); } String loginToken = matcher.group(1); List<NameValuePair> postData = new ArrayList<NameValuePair>(); postData.add(new BasicNameValuePair("login:userId", username)); postData.add(new BasicNameValuePair("login:pin", password)); postData.add(new BasicNameValuePair("login", "login")); postData.add(new BasicNameValuePair("javax.faces.ViewState", viewState)); postData.add(new BasicNameValuePair("login:time", Long.toString(System.currentTimeMillis()))); postData.add(new BasicNameValuePair("login:loginToken", loginToken)); postData.add(new BasicNameValuePair("login:loginButton", "login:loginButton")); return new LoginPackage(weblogin, postData, response, weblogin.getCurrentURI()); }
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); }
private void updateCreditCardTransactions(Account account, Urllib urlopen) throws BankException, IOException { HttpResponse httpResponse = urlopen.openAsHttpResponse( getResourceUri("engagement/cardaccount/" + mIdMap.get(account.getId())), false); if (httpResponse.getStatusLine().getStatusCode() != 200) { Log.i(TAG, "Couldn't find transactions for creditcard"); account.setTransactions(Collections.<Transaction>emptyList()); return; } CardAccountResponse response = readJsonValue(httpResponse.getEntity().getContent(), CardAccountResponse.class); List<Transaction> transactions = new ArrayList<Transaction>(); transactions.addAll(transformCardTransactions(response.getTransactions())); transactions.addAll(transformCardTransactions(response.getReservedTransactions())); account.setTransactions(transactions); }
@Override public void updateTransactions(Account account, Urllib urlopen) throws LoginException, BankException, IOException { super.updateTransactions(account, urlopen); if (account.getType() == Account.CCARD) { updateCreditCardTransactions(account, urlopen); return; } else if (account.getType() != Account.REGULAR) { return; } else if (mIdMap.get(account.getId()) == null) { return; } HttpResponse httpResponse = urlopen.openAsHttpResponse( getResourceUri("engagement/transactions/" + mIdMap.get(account.getId())), false); TransactionsResponse response = readJsonValue(httpResponse.getEntity().getContent(), TransactionsResponse.class); List<Transaction> transactions = new ArrayList<Transaction>(); transactions.addAll(transformTransactions(response.getTransactions())); transactions.addAll(transformTransactions(response.getReservedTransactions())); account.setTransactions(transactions); }
public void closeConnection() { if (urlopen != null) { urlopen.close(); } }