Authentication result parsing
This commit is contained in:
parent
0f019ebc34
commit
4a3136a766
@ -81,6 +81,7 @@
|
|||||||
x_server: this.server,
|
x_server: this.server,
|
||||||
x_user: this.user,
|
x_user: this.user,
|
||||||
banner: null,
|
banner: null,
|
||||||
|
authinfo: null,
|
||||||
accesscode: null,
|
accesscode: null,
|
||||||
verifycode: null
|
verifycode: null
|
||||||
};
|
};
|
||||||
@ -121,7 +122,7 @@
|
|||||||
this.logout();
|
this.logout();
|
||||||
if(this.x_client = await (this.host ? vistax.Client.fromCookie(this.secret, this.host) : vistax.Client.fromCookie(this.secret))) {
|
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();
|
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();
|
var user = await this.x_client.XUS_GET_USER_INFO();
|
||||||
this.x_user = user[0] ? user : null
|
this.x_user = user[0] ? user : null
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
@ -136,20 +137,21 @@
|
|||||||
} else {
|
} else {
|
||||||
this.fail = true;
|
this.fail = true;
|
||||||
this.host = undefined;
|
this.host = undefined;
|
||||||
|
this.authinfo = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async login(evt) {
|
async login(evt) {
|
||||||
if(this.x_client) {
|
if(this.x_client) {
|
||||||
var res = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
|
this.authinfo = await ((this.accesscode && this.verifycode) ? this.x_client.authenticate(this.accesscode + ';' + this.verifycode) : this.x_client.authenticate());
|
||||||
if(!!res.result[0]) {
|
if(this.authinfo.duz) {
|
||||||
var user = await this.x_client.XUS_GET_USER_INFO();
|
var user = await this.x_client.XUS_GET_USER_INFO();
|
||||||
this.x_user = user[0] ? user : null
|
this.x_user = user[0] ? user : null
|
||||||
} else this.x_user = null;
|
} else this.x_user = null;
|
||||||
this.$emit('update:user', this.x_user);
|
this.$emit('update:user', this.x_user);
|
||||||
this.show = !this.x_user;
|
this.show = !this.x_user;
|
||||||
this.$emit('update:server', this.x_server = (await this.x_client.serverinfo()).result);
|
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) {
|
async logout(evt) {
|
||||||
if(this.x_client) {
|
if(this.x_client) {
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
methods: {
|
methods: {
|
||||||
async submit(payload) {
|
async submit(payload) {
|
||||||
if((this.ien) && (this.dfn) && (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 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);
|
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);
|
console.log(res);
|
||||||
@ -52,8 +52,8 @@
|
|||||||
() => (this.client, this.ien, {}),
|
() => (this.client, this.ien, {}),
|
||||||
async () => {
|
async () => {
|
||||||
if((this.client) && (this.ien)) {
|
if((this.client) && (this.ien)) {
|
||||||
var userinfo = await this.client.userinfo();
|
var authinfo = await this.client.authinfo();
|
||||||
var user_ien = userinfo && userinfo.result ? userinfo.result[0] : '';
|
var user_ien = authinfo && authinfo.success ? authinfo.duz : '';
|
||||||
this.dlgname = await this.client.ORWDXM_DLGNAME(this.ien);
|
this.dlgname = await this.client.ORWDXM_DLGNAME(this.ien);
|
||||||
if(this.dlgname.BaseDialogIEN != this.ien) console.warn('IEN =', this.ien, '|', 'BaseDialogIEN =', this.dlgname.BaseDialogIEN);
|
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);
|
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) {
|
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]);
|
return new TplFS(client, null, (await client.TIU_TEMPLATE_GETPROOT(user_ien))[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ export async function serverinfo(cid) {
|
|||||||
})).json();
|
})).json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function userinfo(cid) {
|
export async function authinfo(cid) {
|
||||||
return await (await fetch('/v1/vista/' + cid + '/userinfo', {
|
return await (await fetch('/v1/vista/' + cid + '/authinfo', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: '{}'
|
body: '{}'
|
||||||
@ -47,5 +47,5 @@ export async function authenticate(cid, avcode=null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default window.vista = {
|
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_text = data => data !== '' ? data.join('\r\n') : data;
|
||||||
export const d_parse_array = data => data !== '' ? 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) {
|
export const d_parse_orderdialogs = (data, columns=['IEN', 'windowFormId', 'displayGroupId', 'type', 'displayText']) => data.map(function(row) {
|
||||||
row = row.split('^');
|
row = row.split('^');
|
||||||
row = [...row[0].split(';'), row[1]];
|
row = [...row[0].split(';'), row[1]];
|
||||||
@ -240,11 +242,11 @@ export function Client(cid, secret) {
|
|||||||
return heartbeat = window.setInterval(this.XWB_IM_HERE, interval);
|
return heartbeat = window.setInterval(this.XWB_IM_HERE, interval);
|
||||||
}
|
}
|
||||||
this.serverinfo = () => vista.serverinfo(cid);
|
this.serverinfo = () => vista.serverinfo(cid);
|
||||||
this.userinfo = () => vista.userinfo(cid);
|
this.authinfo = aflow(() => vista.authinfo(cid), d_unwrap, d_parse_authinfo);
|
||||||
this.authenticate = (avcode=null) => vista.authenticate(cid, avcode);
|
this.authenticate = aflow((avcode=null) => vista.authenticate(cid, avcode), d_unwrap, d_parse_authinfo);
|
||||||
|
|
||||||
if(!localstate.encfs) localstate.encfs = tplfs_randpassword();
|
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.encfs = async () => this._encfs ? this._encfs : (this._encfs = await EncFS.fromPassword(await this.tplfs(), localstate.encfs));
|
||||||
|
|
||||||
this.remotestate = reactive({});
|
this.remotestate = reactive({});
|
||||||
|
6
main.py
6
main.py
@ -92,11 +92,11 @@ def application():
|
|||||||
logger.exception(request.url)
|
logger.exception(request.url)
|
||||||
return jsonify_error(ex, id=request.json.get('id'))
|
return jsonify_error(ex, id=request.json.get('id'))
|
||||||
|
|
||||||
@app.post('/v1/vista/<cid>/userinfo')
|
@app.post('/v1/vista/<cid>/authinfo')
|
||||||
def cb_userinfo(cid):
|
def cb_authinfo(cid):
|
||||||
try:
|
try:
|
||||||
client = clients[cid]
|
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:
|
except Exception as ex:
|
||||||
logger.exception(request.url)
|
logger.exception(request.url)
|
||||||
return jsonify_error(ex, id=request.json.get('id'))
|
return jsonify_error(ex, id=request.json.get('id'))
|
||||||
|
12
rpc.py
12
rpc.py
@ -112,7 +112,7 @@ class ClientSync(object):
|
|||||||
self.recv_rpc_msg = recv_rpc_msg(self.sock)
|
self.recv_rpc_msg = recv_rpc_msg(self.sock)
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self._server = { 'host': host, 'port': port }
|
self._server = { 'host': host, 'port': port }
|
||||||
self._user = None
|
self._auth = None
|
||||||
self.context = 'XUS SIGNON'
|
self.context = 'XUS SIGNON'
|
||||||
if TCPConnect and (res := self.TCPConnect(self.sock.getsockname()[0], '0', socket.gethostname())) != 'accept':
|
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)
|
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))
|
res = self('XUS ESSO VALIDATE', RPCType(tuple(identity[i:i+200] for i in range(0, len(identity), 200)), RPCType.GLOBAL))
|
||||||
else:
|
else:
|
||||||
res = self('XUS AV CODE', XWBHash_encrypt(identity))
|
res = self('XUS AV CODE', XWBHash_encrypt(identity))
|
||||||
if res[0] == '0' or res[2] != '0':
|
self._auth = res if res[0] != '0' else None
|
||||||
raise RPCExcAuth(res[3], res)
|
|
||||||
self._user = res
|
|
||||||
return res
|
return res
|
||||||
def keepalive(self, interval=None, *, context=('XUS SIGNON',)):
|
def keepalive(self, interval=None, *, context=('XUS SIGNON',)):
|
||||||
import time
|
import time
|
||||||
@ -188,7 +186,7 @@ class ClientAsync(object):
|
|||||||
self.arecv_rpc_msg = arecv_rpc_msg(self.reader)
|
self.arecv_rpc_msg = arecv_rpc_msg(self.reader)
|
||||||
self.lock = asyncio.Lock()
|
self.lock = asyncio.Lock()
|
||||||
self._server = { 'host': host, 'port': port, 'info': None }
|
self._server = { 'host': host, 'port': port, 'info': None }
|
||||||
self._user = None
|
self._auth = None
|
||||||
self.context = 'XUS SIGNON'
|
self.context = 'XUS SIGNON'
|
||||||
if TCPConnect and (res := await self.TCPConnect(self.writer.get_extra_info('sockname')[0], '0', socket.gethostname())) != 'accept':
|
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)
|
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))
|
res = await self('XUS ESSO VALIDATE', RPCType(tuple(identity[i:i+200] for i in range(0, len(identity), 200)), RPCType.GLOBAL))
|
||||||
else:
|
else:
|
||||||
res = await self('XUS AV CODE', XWBHash_encrypt(identity))
|
res = await self('XUS AV CODE', XWBHash_encrypt(identity))
|
||||||
if res[0] == '0' or res[2] != '0':
|
self._auth = res if res[0] != '0' else None
|
||||||
raise RPCExcAuth(res[3], res)
|
|
||||||
self._user = res
|
|
||||||
return res
|
return res
|
||||||
async def keepalive(self, interval=None, *, context=('XUS SIGNON',)):
|
async def keepalive(self, interval=None, *, context=('XUS SIGNON',)):
|
||||||
interval = interval or 0.45*float((await self.XWB_GET_BROKER_INFO(context=context))[0])
|
interval = interval or 0.45*float((await self.XWB_GET_BROKER_INFO(context=context))[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user