associate cryps with account:

This commit is contained in:
ntr
2018-09-17 00:03:04 +10:00
parent a78b796c55
commit f53853e2ac
5 changed files with 62 additions and 55 deletions
+13 -13
View File
@@ -6,9 +6,9 @@ const assert = require('assert');
const ws = new WebSocket('ws://localhost:40000');
ws.binaryType = 'arraybuffer';
// handle user auth within the socket itself
// handle account auth within the socket itself
// https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
let user = null;
let account = null;
function error_toast(err) {
console.error(err);
@@ -19,12 +19,12 @@ function error_toast(err) {
});
}
function user_login(res) {
[struct, user] = res;
function account_login(res) {
[struct, account] = res;
user = user;
account = account;
console.log(user);
console.log(account);
return send({ method: 'cryp_spawn', params: { name: 'drake' }});
}
@@ -34,8 +34,8 @@ function new_cryp(cryp) {
const handlers = {
'cryp_spawn': new_cryp,
'user_login': user_login,
'user_create': user_login,
'account_login': account_login,
'account_create': account_login,
};
function on_message(event) {
@@ -51,14 +51,14 @@ function on_message(event) {
}
function send(msg) {
msg.token = user && user.token;
msg.token = account && account.token;
ws.send(cbor.encode(msg));
}
// Connection opened
ws.addEventListener('open', function (event) {
// send({ method: 'user_create', params: { name: 'ntr', password: 'grepgrepgrep' }});
send({ method: 'user_login', params: { name: 'ntr', password: 'grepgrepgrep' }});
// send({ method: 'account_create', params: { name: 'ntr', password: 'grepgrepgrep' }});
send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' }});
});
// Listen for messages
@@ -66,10 +66,10 @@ ws.addEventListener('message', on_message);
ws.addEventListener('error', function (event) {
console.error('WebSocket error', event);
user = null;
account = null;
});
ws.addEventListener('close', function (event) {
console.error('WebSocket closed', event);
user = null;
account = null;
});