Commit 88ae3c2a authored by Laurent's avatar Laurent

Merge branch 'master' into iguana

parents 38be48f8 cdf9392e
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="37"
android:versionName="0.0.37">
android:versionCode="40"
android:versionName="0.0.40">
<supports-screens
android:smallScreens="true"
......
......@@ -483,8 +483,13 @@ export class LibraryController extends Controller {
if (!this._view)
return this;
this._view.getViewById("loans").notifyPullToRefreshFinished();
this._view.getViewById("holds").notifyPullToRefreshFinished();
let loans = this._view.getViewById("loans")
if (loans != undefined)
loans.notifyPullToRefreshFinished();
let holds = this._view.getViewById("holds")
if (holds != undefined)
holds.notifyPullToRefreshFinished();
let indicator = this._view.getViewById("activity-indicator");
if (!indicator || (undefined == indicator.animate))
......
import * as Application from 'application';
declare var android: any;
declare var java: any;
import * as Application from 'application'
declare var android: any
declare var java: any
export class Cookies {
public syncHttpToWebViews(): Cookies {
new WebViewCookies().setCookies(this.getCookies());
return this;
new WebViewCookies().setCookies(this.getCookies())
return this
}
public setCookies(cookies:Array<java.net.HttpCookie>): Cookies {
new JavaHTTPCookies().setCookies(cookies);
return this;
public setCookies(cookies: Map<java.net.URI, Array<java.net.HttpCookie>>): Cookies {
new JavaHTTPCookies().setCookies(cookies)
return this
}
public getCookies(): Array<java.net.HttpCookie> {
return new JavaHTTPCookies().getCookies();
public getCookies(): Map<java.net.URI, Array<java.net.HttpCookie>> {
return new JavaHTTPCookies().getCookies()
}
public clearCookies(): Cookies {
new JavaHTTPCookies().clearCookies();
new WebViewCookies().clearCookies();
return this;
new JavaHTTPCookies().clearCookies()
new WebViewCookies().clearCookies()
return this
}
}
......@@ -32,49 +32,51 @@ export class Cookies {
class JavaHTTPCookies {
public getCookieStore(): java.net.CookieStore {
let cookie_manager = java.net.CookieHandler.getDefault();
let cookie_manager = java.net.CookieHandler.getDefault()
return (null == cookie_manager)
? null
: cookie_manager.getCookieStore();
: cookie_manager.getCookieStore()
}
public getCookies(): Array<java.net.HttpCookie> {
let cookies:Array<java.net.HttpCookie> = new Array<java.net.HttpCookie>();
let cookie_store = this.getCookieStore();
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()
if (null == cookie_store)
return cookies;
let cookie_list = cookie_store.getCookies();
for (let i = 0; i < cookie_list.size(); i++) {
cookies.push(cookie_list.get(i));
};
return cookies;
return cookies
let uris = cookie_store.getURIs()
for (let i = 0; i < uris.size(); i++) {
let uri = uris.get(i)
cookies.set(uri, Array.from(cookie_store.get(uri).toArray()))
}
return cookies
}
public setCookies(cookies: Array<java.net.HttpCookie>): JavaHTTPCookies {
let cookie_store = this.getCookieStore();
public setCookies(cookies: Map<java.net.URI, Array<java.net.HttpCookie>>): JavaHTTPCookies {
let cookie_store = this.getCookieStore()
if (null == cookie_store)
return this;
return this
cookie_store.removeAll();
cookies.forEach((cookie) => {
cookie_store.add(new java.net.URI(cookie.getDomain()),
cookie);
});
java.net.CookieHandler.getDefault().setCookiePolicy(java.net.CookiePolicy.ACCEPT_ALL)
cookie_store.removeAll()
cookies.forEach( (uri_cookies:Array<java.net.HttpCookie>, uri: java.net.URI) => {
uri_cookies.forEach( (cookie: java.net.HttpCookie) => { cookie_store.add(uri, cookie) })
})
return this;
return this
}
public clearCookies(): JavaHTTPCookies {
let cookie_store = this.getCookieStore();
let cookie_store = this.getCookieStore()
if (null != cookie_store)
cookie_store.removeAll();
return this;
cookie_store.removeAll()
return this
}
}
......@@ -82,23 +84,25 @@ class JavaHTTPCookies {
class WebViewCookies {
public setCookies(cookies: Array<java.net.HttpCookie>): WebViewCookies {
let cookie_manager = android.webkit.CookieManager.getInstance();
cookie_manager.setAcceptCookie(true);
cookie_manager.removeSessionCookie();
cookies.forEach((cookie) => {
cookie_manager.setCookie(cookie.getDomain(), cookie.toString());
});
android.webkit.CookieSyncManager.createInstance(Application.android.context).sync();
cookie_manager.flush();
return this;
public setCookies(cookies: Map<java.net.URI, Array<java.net.HttpCookie>>): WebViewCookies {
let cookie_manager = android.webkit.CookieManager.getInstance()
cookie_manager.setAcceptCookie(true)
cookie_manager.removeSessionCookie()
cookies.forEach( (uri_cookies:Array<java.net.HttpCookie>, uri: java.net.URI) => {
uri_cookies.forEach( (cookie: java.net.HttpCookie) => {
cookie_manager.setCookie(uri.toString(), cookie.toString())
})
})
android.webkit.CookieSyncManager.createInstance(Application.android.context).sync()
cookie_manager.flush()
return this
}
public clearCookies(): WebViewCookies {
android.webkit.CookieManager.getInstance().removeSessionCookie();
return this;
android.webkit.CookieManager.getInstance().removeSessionCookie()
return this
}
}
import * as http from 'http';
import {Koha} from './koha';
import {WrongLoginPassword} from './wrong-login-password';
import {Account} from '../../models';
import * as cheerio from 'cheerio';
import * as UrlParse from 'url-parse';
export class KohaCas extends Koha {
public getIdentifier(): string {
......@@ -21,7 +24,8 @@ export class KohaCas extends Koha {
protected _signIn(account): Promise<any> {
if (!(account.credentials['login'] && account.credentials['password']))
return Promise.reject(new WrongLoginPassword());
account.setCookies([])
return this
.request(account,
{ url: account.getUrl() })
......@@ -40,6 +44,7 @@ export class KohaCas extends Koha {
username: account.credentials['login'],
password: account.credentials['password'],
execution: form_inputs['execution'],
geolocation: '',
'_eventId': form_inputs['_eventId'],
'lt': form_inputs['lt'] || '',
'submit': form_inputs['submit']
......@@ -49,16 +54,10 @@ export class KohaCas extends Koha {
.request(account,
{ url: cas_link,
method: "POST",
dontFollowRedirects: true,
content: this._encodeForm(form_data),
headers: {"Content-Type": "application/x-www-form-urlencoded"} });
})
})
.then( (response) => {
return (response.statusCode == 302)
? this.request(account, { url: response.headers['Location'] })
: response
})
.then( (response) => {
let $ = cheerio.load(response.content.toString());
let cas_link = $('a[href*="/cas/login?service="]').attr('href');
......@@ -77,10 +76,9 @@ export class KohaCas extends Koha {
$('form input')
.filter( (i, elem) => { return $(elem).attr('name') != undefined; } )
.each((i, elem) => {
let input = $(elem);
form_data[input.attr('name')] = input.attr('value') || '';
let input = $(elem)
form_data[input.attr('name')] = input.attr('value') || ''
});
return form_data;
}
}
......@@ -143,32 +143,6 @@ export class OrpheeMedia extends PortalAdapter {
}
protected _requestWorkaroundCookies(account: Account, options: any): Promise<http.HttpResponse> {
options.dontFollowRedirects = true;
let cookies = account.getCookies();
if (cookies.length > 0) {
options.headers['Cookie'] = cookies.map( (cookie) => {
return cookie.toString();
});
account.setCookies([]);
}
return this
.request(account, options)
.then( (response) => {
if (account.getCookies().length == 0)
account.setCookies(cookies);
if (response.statusCode == 301 || response.statusCode == 302 || response.statusCode == 303)
return this.request( account,
{ url: account.getUrl() });
return response;
});
}
protected _signIn(account): Promise<any> {
if (!(account.credentials['login'] && account.credentials['password']))
return Promise.reject(new WrongLoginPassword());
......@@ -217,11 +191,11 @@ export class OrpheeMedia extends PortalAdapter {
return this
._requestWorkaroundCookies(account,
{ url: account.getUrl(),
method: "POST",
content: this._encodeForm(login_data),
headers: {"Content-Type": "application/x-www-form-urlencoded" } })
.request(account,
{ url: account.getUrl(),
method: "POST",
content: this._encodeForm(login_data),
headers: {"Content-Type": "application/x-www-form-urlencoded" } })
.then( (response) => {
return this._handleLoginResponse(account, response, account.getUrl())
} );
......
......@@ -4,5 +4,5 @@
},
"main": "app.js",
"name": "bibapp",
"version": "0.0.37"
"version": "0.0.40"
}
<Page xmlns:accounts="views/accounts">
<Page.actionBar>
<ActionBar title="{{ L('account_parameters') }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
</ActionBar>
<DockLayout stretchLastChild="true">
<StackLayout dock="bottom">
......
<Page xmlns:nsDrawer="nativescript-ui-sidedrawer" xmlns:shared="views/shared" loaded="{{ onPageLoaded }}">
<Page.actionBar>
<ActionBar title="{{ page_title }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goHomeAction }}"/>
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
<ActionItem text="{{ L('menu) }}" tap="{{ toggleDrawerAction }}">
<ActionItem.actionView>
......
<Page xmlns:nsDrawer="nativescript-ui-sidedrawer" xmlns:lv="nativescript-ui-listview" xmlns:shared="views/shared" loaded="{{ onPageLoaded }}">
<Page.actionBar>
<ActionBar title="{{ L('novelties') }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goHomeAction }}"/>
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
<ActionItem text="{{ L('menu) }}" tap="{{ toggleDrawerAction }}">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
......
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