Commit 761f1fe6 authored by Laurent's avatar Laurent

Iguana: set IguanaLogin cookie

parent 842ff209
......@@ -3,13 +3,13 @@ declare var android: any
declare var java: any
export class Cookies {
public syncHttpToWebViews(): Cookies {
public syncHttpToWebViews(): this {
new WebViewCookies().setCookies(this.getCookies())
return this
}
public setCookies(cookies: Map<java.net.URI, Array<java.net.HttpCookie>>): Cookies {
public setCookies(cookies: Map<java.net.URI, Array<java.net.HttpCookie>>): this {
new JavaHTTPCookies().setCookies(cookies)
return this
}
......@@ -20,6 +20,12 @@ export class Cookies {
}
public addCookie(uri:string, name: string, value: string): this {
new JavaHTTPCookies().addCookie(uri, name, value)
return this;
}
public clearCookies(): Cookies {
new JavaHTTPCookies().clearCookies()
new WebViewCookies().clearCookies()
......@@ -39,6 +45,18 @@ class JavaHTTPCookies {
}
public addCookie(uri:string, name: string, value: string): this {
let cookie_store = this.getCookieStore()
if (null == cookie_store)
return this
cookie_store.add(new java.net.URI(uri),
new java.net.HttpCookie(name, value));
return this;
}
public getCookies(): Map<java.net.URI, Array<java.net.HttpCookie>> {
let cookies:Map<java.net.URI, Array<java.net.HttpCookie>> = new Map<java.net.URI, Array<java.net.HttpCookie>>()
let cookie_store = this.getCookieStore()
......
export declare class Cookies {
public syncHttpToWebViews(): Cookies;
public setCookies(cookies:any): Cookies;
public syncHttpToWebViews(): this;
public setCookies(cookies:any): this;
public getCookies(): Array<any>;
public clearCookies(): Cookies;
public clearCookies(): this;
public addCookie(uri:string, name: string, value: string): this;
}
......@@ -4,10 +4,22 @@ import * as http from 'http';
export class NSHTTPClient implements HTTPClient {
public request(options: any): Promise<http.HttpResponse> {
console.dir([ 'on request', (new Cookies()).getCookies(), options]);
console.dir([ 'on request', this._printCookies(), options]);
return http.request(options).then( (response) => {
console.dir([ 'on response', (new Cookies()).getCookies(), response.headers]);
console.dir([ 'on response', this._printCookies(), response.headers]);
return response;
});
}
protected _printCookies(): Array<String> {
let desc = new Array<String>()
new Cookies().getCookies().forEach( (cookies, uri) => {
cookies.forEach( (cookie) => {
desc.push(uri + ': ' + cookie.toString())
})
})
return desc
}
}
import {PortalAdapter} from './adapter'
import * as cheerio from 'cheerio'
import * as xmljs from 'xml-js'
import {Account, Loan, Hold} from '../../models'
import {Account, Cookies, Loan, Hold} from '../../models'
import {WrongLoginPassword} from './wrong-login-password'
import * as UrlParse from 'url-parse';
......@@ -144,6 +144,7 @@ export class IguanaV3 extends PortalAdapter {
})
.then( (datas) => {
let token = datas['Token']['_text'];
let form_data = {
BorrowerId: datas['BorrowerId']['_text'],
Category: datas['Category']['_text'],
......@@ -156,16 +157,22 @@ export class IguanaV3 extends PortalAdapter {
Profile: 'Iguana',
SessionId: datas['SessionId']['_text'],
tempList: '',
Token: datas['Token']['_text'],
Token: token,
UserAge: datas['UserAge']['_text'],
UserName: datas['UserName']['_text'],
ValidRequests: 'Welcome,CurrentLoans,LoanHistory,PaymentsHistory,CurrentReservations,Interests,ReadingLists,LinkedAccounts,SearchFilter,ViewId',
ViewId: ''
}
let origin = new UrlParse(account.getUrl()).origin
let cookies = new Cookies();
cookies.addCookie(origin + '/iguana', 'IguanaLogin', token)
account.setCookies(cookies.getCookies());
return this.request(account,
{
url: (new UrlParse(account.getUrl()).origin + '/iguana/Proxy.SetLogon.cls'),
url: (origin + '/iguana/Proxy.SetLogon.cls'),
method: 'POST',
content: this._encodeForm(form_data),
headers: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment