Authentication result parsing
This commit is contained in:
@ -81,6 +81,7 @@
|
||||
x_server: this.server,
|
||||
x_user: this.user,
|
||||
banner: null,
|
||||
authinfo: null,
|
||||
accesscode: null,
|
||||
verifycode: null
|
||||
};
|
||||
@ -121,7 +122,7 @@
|
||||
this.logout();
|
||||
if(this.x_client = await (this.host ? vistax.Client.fromCookie(this.secret, this.host) : vistax.Client.fromCookie(this.secret))) {
|
||||
this.banner = await this.x_client.XUS_INTRO_MSG();
|
||||
if((await this.x_client.userinfo()).result) try {
|
||||
if((this.authinfo = await this.x_client.authinfo()).success) try {
|
||||
var user = await this.x_client.XUS_GET_USER_INFO();
|
||||
this.x_user = user[0] ? user : null
|
||||
} catch(ex) {
|
||||
@ -136,20 +137,21 @@
|
||||
} else {
|
||||
this.fail = true;
|
||||
this.host = undefined;
|
||||
this.authinfo = null;
|
||||
}
|
||||
},
|
||||
async login(evt) {
|
||||
if(this.x_client) {
|
||||
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
|
||||
if(!!res.result[0]) {
|
||||
this.authinfo = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
|
||||
if(this.authinfo.duz) {
|
||||
var user = await this.x_client.XUS_GET_USER_INFO();
|
||||
this.x_user = user[0] ? user : null
|
||||
} else this.x_user = null;
|
||||
this.$emit('update:user', this.x_user);
|
||||
this.show = !this.x_user;
|
||||
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
|
||||
console.log('Authenticate', res);
|
||||
}
|
||||
console.log('Authenticate', this.authinfo);
|
||||
} else this.authinfo = null;
|
||||
},
|
||||
async logout(evt) {
|
||||
if(this.x_client) {
|
||||
|
@ -40,7 +40,7 @@
|
||||
methods: {
|
||||
async submit(payload) {
|
||||
if((this.ien) && (this.dfn) && (payload)) {
|
||||
var user_ien = (await this.client.userinfo()).result[0];
|
||||
var user_ien = (await this.client.authinfo()).duz;
|
||||
var dgrp = await this.client.ORWDX_DGRP(this.dlgname.BaseDialogName);
|
||||
var res = await client.ORWDX_SAVE(this.dfn, 0/*user_ien*/, 0/*location_ien*/, this.dlgname.BaseDialogName, dgrp, this.dlgname.BaseDialogIEN, ''/*order_ifn*/, payload, '', '', '', 0);
|
||||
console.log(res);
|
||||
@ -52,8 +52,8 @@
|
||||
() => (this.client, this.ien, {}),
|
||||
async () => {
|
||||
if((this.client) && (this.ien)) {
|
||||
var userinfo = await this.client.userinfo();
|
||||
var user_ien = userinfo && userinfo.result ? userinfo.result[0] : '';
|
||||
var authinfo = await this.client.authinfo();
|
||||
var user_ien = authinfo && authinfo.success ? authinfo.duz : '';
|
||||
this.dlgname = await this.client.ORWDXM_DLGNAME(this.ien);
|
||||
if(this.dlgname.BaseDialogIEN != this.ien) console.warn('IEN =', this.ien, '|', 'BaseDialogIEN =', this.dlgname.BaseDialogIEN);
|
||||
this.dlgdef = await this.client.ORWDX_DLGDEF(this.dlgname.BaseDialogName);
|
||||
|
@ -217,7 +217,7 @@ export function TplFS(client, parent, desc) {
|
||||
}
|
||||
|
||||
TplFS.fromUser = async function(client, user_ien=null) {
|
||||
if(!user_ien) user_ien = (await client.userinfo()).result[0];
|
||||
if(!user_ien) user_ien = (await client.authinfo()).duz;
|
||||
return new TplFS(client, null, (await client.TIU_TEMPLATE_GETPROOT(user_ien))[0]);
|
||||
};
|
||||
|
||||
|
@ -30,8 +30,8 @@ export async function serverinfo(cid) {
|
||||
})).json();
|
||||
}
|
||||
|
||||
export async function userinfo(cid) {
|
||||
return await (await fetch('/v1/vista/' + cid + '/userinfo', {
|
||||
export async function authinfo(cid) {
|
||||
return await (await fetch('/v1/vista/' + cid + '/authinfo', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: '{}'
|
||||
@ -47,5 +47,5 @@ export async function authenticate(cid, avcode=null) {
|
||||
}
|
||||
|
||||
export default window.vista = {
|
||||
connect, close, call, serverinfo, userinfo, authenticate
|
||||
connect, close, call, serverinfo, authinfo, authenticate
|
||||
};
|
||||
|
@ -48,6 +48,8 @@ export const d_parse_boolean = data => data != '0';
|
||||
export const d_parse_text = data => data !== '' ? data.join('\r\n') : data;
|
||||
export const d_parse_array = data => data !== '' ? data : [];
|
||||
|
||||
export const d_parse_authinfo = data => data ? { duz: data[0] != '0' ? data[0] : null, device_lock: data[1] != '0', change_verify: data[2] != '0', message: data[3], reserved: data[4], greeting_lines: data[5], greeting: data.slice(6), success: (data[0] != '0') && (data[2] == '0') } : { success: false }
|
||||
|
||||
export const d_parse_orderdialogs = (data, columns=['IEN', 'windowFormId', 'displayGroupId', 'type', 'displayText']) => data.map(function(row) {
|
||||
row = row.split('^');
|
||||
row = [...row[0].split(';'), row[1]];
|
||||
@ -240,11 +242,11 @@ export function Client(cid, secret) {
|
||||
return heartbeat = window.setInterval(this.XWB_IM_HERE, interval);
|
||||
}
|
||||
this.serverinfo = () => vista.serverinfo(cid);
|
||||
this.userinfo = () => vista.userinfo(cid);
|
||||
this.authenticate = (avcode=null) => vista.authenticate(cid, avcode);
|
||||
this.authinfo = aflow(() => vista.authinfo(cid), d_unwrap, d_parse_authinfo);
|
||||
this.authenticate = aflow((avcode=null) => vista.authenticate(cid, avcode), d_unwrap, d_parse_authinfo);
|
||||
|
||||
if(!localstate.encfs) localstate.encfs = tplfs_randpassword();
|
||||
this.tplfs = async () => this._tplfs ? this._tplfs : (this._tplfs = await TplFS.fromUser(this, (await this.userinfo()).result[0]));
|
||||
this.tplfs = async () => this._tplfs ? this._tplfs : (this._tplfs = await TplFS.fromUser(this, (await this.authinfo()).duz));
|
||||
this.encfs = async () => this._encfs ? this._encfs : (this._encfs = await EncFS.fromPassword(await this.tplfs(), localstate.encfs));
|
||||
|
||||
this.remotestate = reactive({});
|
||||
|
Reference in New Issue
Block a user