7RKEQK2KPXJ2MEHPVSY7ROMHW6FTTKCXSMZV5MEXPFZKESZQYUUAC
63VXWIHIAKGK7J4VTNRUAG2V32N2QUSWFELB6GD34S54FGRWAPCQC
E4HFJ4L4PAGV7R7EXVG2B2CWDGGW7XWU4D37VURZ66HZ3ILHCFUAC
MM3HQWNEUZVOGQ3WWBTECBY6F47SN4U43I5UNDOAFWO3R7U5XPBAC
VO5G3FF3NDOKCIF2OU7G257R3XIPTFDCAMDTOVKHKOB5Z3I55KDQC
Y4W4MACPKH3IVO6JIQYGN4V5LR6EM6RPZEJ4RHH6ZBZUDA63AGRQC
WYTMZJFYVKHR4QH7AV5JUNWXT6NAC5NNQNPZCQSDI6LGI7DVXFYAC
2FPZGFF5PCGNV45HOB6TROMJFPURHPXM7YSPWNXCHFJS7EICVKQAC
const { Pool } = require('pg');
const pool = new Pool();
require('dotenv').config();
require('fs').readFileSync(0).toString().slice(0, -1).split('\n').forEach(l => {
let [email, hash, genes] = l.split('\t');
genes = new Map(genes.slice(1, -1).split(',').map(r => {
let k = r.split('_');
let v = k.pop();
k = k.join('_');
if(v === 'vv') {
v = 'Val/Val';
} else if(v === 'vm') {
v = 'Val/Met';
} else if(v === 'mm') {
v = 'Met/Met';
} else if(v === 'inc') {
v = 'inconclusive';
} else if(v === 'tt') {
v = 'T/T';
} else if(v === 'ct') {
v = 'C/T';
} else if(v === 'cc') {
v = 'C/C';
} else if(v === '11') {
v = '*1/*1';
} else if(v === '13') {
v = '*1/*3';
} else if(v === '33') {
v = '*3/*3';
} else if(v === '12') {
v = '*1/*2';
} else if(v === '22') {
v = '*2/*2';
} else if(v === '117') {
v = '*1/*17';
} else if(v === '1717') {
v = '*17/*17';
}
return [k, v]
}));
let keys = [...genes.keys()];
let values = [...genes.values()];
try {
pool.query(
`insert into usr (email, webportal_hash, ${keys.join(',')})
values ($1, $2, ${values.map((_, i) => '$' + (i + 3)).join(',')})
on conflict (email) do nothing`,
[email, hash].concat(values)
);
} catch(e) {
console.log(e);
}
});
"bcrypt": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-4.0.1.tgz",
"integrity": "sha512-hSIZHkUxIDS5zA2o00Kf2O5RfVbQ888n54xQoF/eIaquU4uaLxK8vhhBdktd0B3n2MjkcAWzv4mnhogykBKOUQ==",
"requires": {
"node-addon-api": "^2.0.0",
"node-pre-gyp": "0.14.0"
}
},
desensitize(user);
user.token = token.toString('base64');//yuck, since json can't send binary, need to base64 encode. fyi base64 is smaller than hex(base16)
//if remember me on client side, store in localstorage. else do nothing with token
//on subsequent new sockets, auto_login with token. token will be invalid(undefined) if remember me was not checked
ws.send(JSON.stringify({
response_ID: request_ID,
data: user
}));
//disallow multiple sockets with same credentials
let old = authenticated.get(user.user_id);
if(old !== undefined) {
delete old.user_ID;
delete old.user_type;
//old.send()logout event
}
authenticated.set(user.user_id, ws);
ws.publish('user/authenticated', JSON.stringify({
what: 'user/authenticated',//tbd
how: 'update',
data: authenticated.size
}));
} else if(await bcrypt.compare(parameters.passphrase + 'a7da287aa2db01ab44144e98f5c5a11edc8f4572c0bd77fcd4d5f036534ab9eb95ff4b9ee2a0dcc32a5aecc3290610ffbfd46c8e911f637e366fd0ec90621252', user.webportal_hash)) {
ws.user_ID = user.user_id;
ws.user_type = user.type;
let token = await randomBytes(128);
await pool.query('update usr set token_hash = $1, passphrase_hash = $3, webportal_hash = null where user_id = $2', [crypto.createHash('BLAKE2b512').update(token).digest(), user.user_id, await argon2.hash(parameters.passphrase)]);//update to blake3 once it's available in openSSL