Commit fdbcfa90 authored by laurent l's avatar laurent l

more ios port

parent 7b477bb5
......@@ -2,22 +2,22 @@ import {Account, Cookies} from '../../models';
import {WebView} from 'ui/web-view';
export class OAuthWebViewClient {
protected static _onTokenSet: any;
protected static _onError: any;
protected _view: WebView;
public constructor(view:WebView) {
this._view = view;
let WVClient = (<any>android.webkit.WebViewClient).extend({
shouldOverrideUrlLoading: (_webview, page_url) => {
protected static _onTokenSet: any;
protected static _onError: any;
protected _view: WebView;
public constructor(view:WebView) {
this._view = view;
let WVClient = (<any>android.webkit.WebViewClient).extend({
shouldOverrideUrlLoading: (_webview, page_url) => {
if (typeof page_url === 'object') // android 7.1.1 compatibility
page_url = page_url.getUrl().toString();
let matches = page_url.match(/.*token=(.*)$/);
if (matches) {
let token = matches[1];
OAuthWebViewClient._onTokenSet(token);
let token = matches[1];
OAuthWebViewClient._onTokenSet(token);
new Cookies().clearCookies();
return true;
}
......@@ -27,30 +27,30 @@ export class OAuthWebViewClient {
return true;
}
return false;
},
return false;
},
onPageFinished: (_webview, page_url) => {
},
onPageStarted: (_webview, page_url, favicon) => {
}});
onPageFinished: (_webview, page_url) => {
},
onPageStarted: (_webview, page_url, favicon) => {
}});
this._view.android.setWebViewClient(new WVClient());
}
this._view.android.setWebViewClient(new WVClient());
}
public login(account: Account): Promise<string> {
public login(account: Account): Promise<string> {
new Cookies().clearCookies();
return new Promise((resolve, reject) => {
OAuthWebViewClient._onTokenSet = resolve;
OAuthWebViewClient._onError = reject;
return new Promise((resolve, reject) => {
OAuthWebViewClient._onTokenSet = resolve;
OAuthWebViewClient._onError = reject;
this._view.src = account.getUrl()
+ '/auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize';
});
}
this._view.src = account.getUrl()
+ '/auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize';
});
}
}
......@@ -2,13 +2,21 @@ import {Account} from '../../models';
import {WebView} from 'ui/web-view';
export class OAuthWebViewClient {
public constructor(view:WebView) {
}
protected _view: WebView
public constructor(view:WebView) {
this._view = view
}
public login(account: Account): Promise<string> {
return new Promise((resolve, reject) => {
});
}
public login(account: Account): Promise<string> {
return new Promise((resolve, reject) => {
let url = account.getUrl()
+ 'auth/oauth/response_type/code/id_profil/1/client_id/'
+ L('app_name')
+ '?redirect_uri=bibapp://authorize'
console.log(url)
this._view.src = url
})
}
}
export class Cookies {
public syncHttpToWebViews(): Cookies {
return this;
public syncHttpToWebViews(): this {
return this
}
public setCookies(cookies:Array<any>): Cookies {
return this;
public setCookies(cookies:Array<any>): this {
return this
}
public getCookies(): Array<any> {
return new Array();
return new Array()
}
public clearCookies(): this {
return this
}
public addCookie(uri:string, name: string, value: string): this {
return this
}
}
......@@ -5,7 +5,7 @@ import * as http from 'http';
export class NSHTTPClient implements HTTPClient {
public request(options: any): Promise<http.HttpResponse> {
console.dir([ 'on request', this._printCookies(), options]);
return http.request(options).then( (response) => {
return http.request(options).then( (response) => {
console.dir([ 'on response', this._printCookies(), response.headers]);
return response;
});
......
......@@ -2,13 +2,13 @@
<Page.actionBar>
<ActionBar title="{{ page_title }}" icon="">
</ActionBar>
</Page.actionBar>
</Page.actionBar>
<StackLayout orientation="vertical" id="oauth_authorize">
<StackLayout orientation="horizontal">
<Label text="{{ L('oauth_authorize') }}" />
<ActivityIndicator busy="true" />
</StackLayout>
<WebView id="webView" />
</StackLayout>
<StackLayout orientation="vertical" id="oauth_authorize">
<StackLayout orientation="horizontal">
<Label text="{{ L('oauth_authorize') }}" />
<ActivityIndicator busy="true" />
</StackLayout>
<WebView id="webView" height="100%"/>
</StackLayout>
</Page>
<Page xmlns:nsDrawer="nativescript-ui-sidedrawer" xmlns:shared="views/shared" loaded="{{ onPageLoaded }}">
<Page.actionBar>
<Page.actionBar>
<ActionBar title="{{ page_title }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
......@@ -9,18 +9,18 @@
</ActionItem.actionView>
</ActionItem>
</ActionBar>
</Page.actionBar>
</Page.actionBar>
<nsDrawer:RadSideDrawer id="sideDrawer" drawerLocation="Right" drawerTransition="PushTransition">
<nsDrawer:RadSideDrawer.drawerContent xmlns:nsDrawer="nativescript-pro-ui/sidedrawer">
<shared:sidedrawer />
</nsDrawer:RadSideDrawer.drawerContent>
<nsDrawer:RadSideDrawer id="sideDrawer" drawerLocation="Right" drawerTransition="PushTransition">
<nsDrawer:RadSideDrawer.drawerContent xmlns:nsDrawer="nativescript-pro-ui/sidedrawer">
<shared:sidedrawer />
</nsDrawer:RadSideDrawer.drawerContent>
<nsDrawer:RadSideDrawer.mainContent>
<StackLayout>
<WebView src="{{ website_url }}" />
<StackLayout>
<WebView src="{{ website_url }}" height="100%"/>
<ActivityIndicator busy="true"/>
</StackLayout>
</StackLayout>
</nsDrawer:RadSideDrawer.mainContent>
</nsDrawer:RadSideDrawer>
</Page>
......
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