bugfix
This commit is contained in:
parent
a7c83e4b0d
commit
3f39f5532a
@ -130,6 +130,7 @@ bricks.widgetBuild = async function(desc, widget, data){
|
||||
let opts = desc.options.params || {};
|
||||
var jc = new bricks.HttpJson();
|
||||
var desc1 = await jc.httpcall(url, { "method":method, "params":opts});
|
||||
if (!desc1) return;
|
||||
desc = desc1;
|
||||
klassname = desc.widgettype;
|
||||
}
|
||||
@ -464,7 +465,7 @@ bricks.App = class extends bricks.Layout {
|
||||
bricks.bug = opts.debug || false;
|
||||
bricks.Body = this;
|
||||
this.deviceid = bricks.deviceid(opts.appname || 'appname');
|
||||
this.login_url = opts.login_url;
|
||||
this.login_url = opts.login_url || '/rbac/userpassword_login.ui';
|
||||
this.charsize = this.opts.charsize || 20;
|
||||
this.keyevent_blocked = false;
|
||||
this.char_size = this.observable('charsize', this.charsize);
|
||||
|
@ -97,7 +97,7 @@ bricks.Cols = class extends bricks.VBox {
|
||||
}
|
||||
}
|
||||
async load_first_page(params){
|
||||
var p = bricks.extend({}, this.params);
|
||||
var p = bricks.extend({}, this.data_params);
|
||||
if (params){
|
||||
p = bricks.extend(p, params);
|
||||
}
|
||||
|
@ -121,27 +121,42 @@ bricks.HttpText = class {
|
||||
}
|
||||
}
|
||||
const fetchResult = await fetch(url, _params);
|
||||
var result=null;
|
||||
result = await this.get_result_data(fetchResult);
|
||||
if (fetchResult.ok){
|
||||
var ck = objget(fetchResult.headers, 'Set-Cookie');
|
||||
if (ck){
|
||||
var session = ck.split(';')[0];
|
||||
bricks.app.save_session(session);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
console.log('fetchResult.status=', fetchResult.status, url, 'login url=', bricks.app.login_url);
|
||||
if (fetchResult.status == 401 && bricks.app.login_url){
|
||||
console.log('go to login')
|
||||
return await this.withLoginInfo(url, _params);
|
||||
}
|
||||
const resp_error = {
|
||||
"type":"Error",
|
||||
"message":result.message || 'Something went wrong',
|
||||
"data":result.data || '',
|
||||
"code":result.code || ''
|
||||
};
|
||||
error.info = resp_error;
|
||||
return error;
|
||||
if (fetchResult.status == 403){
|
||||
var w = new bricks.Error({
|
||||
"title":"access error",
|
||||
"auto_open":true,
|
||||
"message":"you are forbidden to access it",
|
||||
"archor":"cc",
|
||||
"cheight":10,
|
||||
"cwidth":16,
|
||||
"timeout":5
|
||||
});
|
||||
return null;
|
||||
}
|
||||
if (! fetchResult.ok){
|
||||
var w = new bricks.Error({
|
||||
"title":"access error",
|
||||
"auto_open":true,
|
||||
"message":"server return error with error code" + fetchResult.status,
|
||||
"archor":"cc",
|
||||
"cheight":10,
|
||||
"cwidth":16,
|
||||
"timeout":5
|
||||
});
|
||||
return null;
|
||||
}
|
||||
var result = await this.get_result_data(fetchResult);
|
||||
var ck = objget(fetchResult.headers, 'Set-Cookie');
|
||||
if (ck){
|
||||
var session = ck.split(';')[0];
|
||||
bricks.app.save_session(session);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async withLoginInfo(url, params){
|
||||
var get_login_info = function(e){
|
||||
@ -149,49 +164,12 @@ bricks.HttpText = class {
|
||||
return e.target.getValue();
|
||||
}
|
||||
var w = await bricks.widgetBuild({
|
||||
"id":"login_form",
|
||||
"widgettype":"urlwidget",
|
||||
"options":{
|
||||
"url":bricks.app.login_url
|
||||
}
|
||||
});
|
||||
var login_info = await new Promise((resolve, reject, w) => {
|
||||
w.bind('submit', (event) => {
|
||||
resolve(event.target.getValue());
|
||||
event.target.dismiss();
|
||||
});
|
||||
w.bind('discard', (event) => {
|
||||
resolve(null);
|
||||
event.target.dismiss()
|
||||
});
|
||||
});
|
||||
if (login_info){
|
||||
this.set_authorization_header(params, lgin_info);
|
||||
const fetchResult = await fetch(url, params);
|
||||
var result=null;
|
||||
result = await this.get_result_data(fetchResult);
|
||||
if (fetchResult.ok){
|
||||
return result;
|
||||
}
|
||||
if (fetchResult.status == 401){
|
||||
return await this.withLoginInfo(url, params);
|
||||
}
|
||||
}
|
||||
const resp_error = {
|
||||
"type":"Error",
|
||||
"message":result.message || 'Something went wrong',
|
||||
"data":result.data || '',
|
||||
"code":result.code || ''
|
||||
};
|
||||
const error = new Error();
|
||||
error.info = resp_error;
|
||||
return error;
|
||||
}
|
||||
set_authorization_header(params, lgin_info){
|
||||
var auth = 'password' + '::' + login_info.user + '::' + login_info.password;
|
||||
var rsa = bricks.app.rsa;
|
||||
var code = rsa.encrypt(auth);
|
||||
self.header.authorization = btoa(code)
|
||||
return null;
|
||||
}
|
||||
async get(url, {headers=null, params=null}={}){
|
||||
return await this.httpcall(url, {
|
||||
|
Loading…
Reference in New Issue
Block a user