Authentication result parsing

This commit is contained in:
Jiang Yio 2023-05-29 18:32:13 -04:00
parent 0f019ebc34
commit 4a3136a766
7 changed files with 26 additions and 26 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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]);
};

View File

@ -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
};

View File

@ -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({});

View File

@ -92,11 +92,11 @@ def application():
logger.exception(request.url)
return jsonify_error(ex, id=request.json.get('id'))
@app.post('/v1/vista/<cid>/userinfo')
def cb_userinfo(cid):
@app.post('/v1/vista/<cid>/authinfo')
def cb_authinfo(cid):
try:
client = clients[cid]
return jsonify_result(client._obj._user, id=request.json.get('id'))
return jsonify_result(client._obj._auth, id=request.json.get('id'))
except Exception as ex:
logger.exception(request.url)
return jsonify_error(ex, id=request.json.get('id'))

12
rpc.py
View File

@ -112,7 +112,7 @@ class ClientSync(object):
self.recv_rpc_msg = recv_rpc_msg(self.sock)
self.lock = threading.Lock()
self._server = { 'host': host, 'port': port }
self._user = None
self._auth = None
self.context = 'XUS SIGNON'
if TCPConnect and (res := self.TCPConnect(self.sock.getsockname()[0], '0', socket.gethostname())) != 'accept':
raise RPCExcInvalidResult('TCPConnect', self.sock.getsockname()[0], '0', socket.gethostname(), res)
@ -148,9 +148,7 @@ class ClientSync(object):
res = self('XUS ESSO VALIDATE', RPCType(tuple(identity[i:i+200] for i in range(0, len(identity), 200)), RPCType.GLOBAL))
else:
res = self('XUS AV CODE', XWBHash_encrypt(identity))
if res[0] == '0' or res[2] != '0':
raise RPCExcAuth(res[3], res)
self._user = res
self._auth = res if res[0] != '0' else None
return res
def keepalive(self, interval=None, *, context=('XUS SIGNON',)):
import time
@ -188,7 +186,7 @@ class ClientAsync(object):
self.arecv_rpc_msg = arecv_rpc_msg(self.reader)
self.lock = asyncio.Lock()
self._server = { 'host': host, 'port': port, 'info': None }
self._user = None
self._auth = None
self.context = 'XUS SIGNON'
if TCPConnect and (res := await self.TCPConnect(self.writer.get_extra_info('sockname')[0], '0', socket.gethostname())) != 'accept':
raise RPCExcInvalidResult('TCPConnect', self.writer.get_extra_info('sockname')[0], '0', socket.gethostname(), res)
@ -229,9 +227,7 @@ class ClientAsync(object):
res = await self('XUS ESSO VALIDATE', RPCType(tuple(identity[i:i+200] for i in range(0, len(identity), 200)), RPCType.GLOBAL))
else:
res = await self('XUS AV CODE', XWBHash_encrypt(identity))
if res[0] == '0' or res[2] != '0':
raise RPCExcAuth(res[3], res)
self._user = res
self._auth = res if res[0] != '0' else None
return res
async def keepalive(self, interval=None, *, context=('XUS SIGNON',)):
interval = interval or 0.45*float((await self.XWB_GET_BROKER_INFO(context=context))[0])