2FPZGFF5PCGNV45HOB6TROMJFPURHPXM7YSPWNXCHFJS7EICVKQAC
"pg-native": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pg-native/-/pg-native-3.0.0.tgz",
"integrity": "sha512-qZZyywXJ8O4lbiIN7mn6vXIow1fd3QZFqzRe+uET/SZIXvCa3HBooXQA4ZU8EQX8Ae6SmaYtDGLp5DwU+8vrfg==",
"requires": {
"libpq": "^1.7.0",
"pg-types": "^1.12.1",
"readable-stream": "1.0.31"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"pg-types": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.13.0.tgz",
"integrity": "sha512-lfKli0Gkl/+za/+b6lzENajczwZHc7D5kiUCZfgm914jipD2kIOIvEkAhZ8GrW3/TUoP9w8FHjwpPObBye5KQQ==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~1.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.0",
"postgres-interval": "^1.1.0"
}
},
"postgres-array": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.3.tgz",
"integrity": "sha512-5wClXrAP0+78mcsNX3/ithQ5exKvCyK5lr5NEEEeGwwM6NJdQgzIJBVxLvRW+huFpX92F2QnZ5CcokH0VhK2qQ=="
},
"readable-stream": {
"version": "1.0.31",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.31.tgz",
"integrity": "sha1-jyUC4LyeOw2huUUgqrtOJgPsr64=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}
}
},
await pool.query('insert into user_account (email, password_hash) values ($1, $2)', [parameters.email, await argon2.hash(parameters.password)]);
//let id = await return_key(...)
await pool.query('insert into user_account (email, password_hash) values ($1, $2) returning id', [parameters.email, await argon2.hash(parameters.password)]);
case 'unregister':
if(isLoggedIn(ws)) {
await pool.query(`delete from user_account where id = $1`, [ws.user_ID]);
authenticated.delete(ws.user_ID);
delete ws.user_ID;
delete ws.user_type;
ws.send(JSON.stringify({
response_ID: request_ID
}));
//ws.publish('/users/' + id? dunno if needed, JSON.stringify(event.json id, remove))
//probably needed, since subscribing to /users/${id} is a given to listen to augment calls or whatever
ws.publish('user/authenticated', JSON.stringify({
what: 'user/authenticated',//tbd
how: 'update',
data: authenticated.size
}));
} else {
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'not logged in'
}));
}
break;
Object.keys(user).forEach((key) => (user[key] == null) && delete user[key]);
//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
//disallow multiple sockets with same credentials
let old = authenticated.get(user.id);
if(old !== undefined) {
delete old.user_ID;
delete old.user_type;
//old.send()logout event
}
authenticated.set(user.id, ws);
ws.publish('user/authenticated', JSON.stringify({
what: 'user/authenticated',//tbd
how: 'update',
data: authenticated.size
}));
let user = (await pool.query('select * from user_account where token_hash = $1', [crypto.createHash('BLAKE2b512').update(Buffer.from(parameters.token, 'base64')).digest()])).rows[0];
let user = (await pool.query('select * from user_account where token_hash = $1 and now() < token_expiry', [crypto.createHash('BLAKE2b512').update(Buffer.from(parameters.token, 'base64')).digest()])).rows[0];
//maybe push expiry? lol don't even have a column for that
//let token = await randomBytes(128);
//await pool.query('update user_account set token_hash = $1 where id = $2', [crypto.createHash('BLAKE2b512').update(token).digest(), user.id]);//update to blake3 once it's available in openSSL
delete user.password_hash;
delete user.token_hash;
delete user.user_type;
//user.token = token.toString('base64');//yuck, since json can't send binary, need to base64 encode. fyi base64 is smaller than hex(base16)
Object.keys(user).forEach((key) => (user[key] == null) && delete user[key]);
desensitize(user);
//disallow multiple sockets with same credentials
let old = authenticated.get(user.id);
if(old !== undefined) {
delete old.user_ID;
delete old.user_type;
//old.send()logout event
}
authenticated.set(user.id, ws);
ws.publish('user/authenticated', JSON.stringify({
what: 'user/authenticated',//tbd
how: 'update',
data: authenticated.size
}));
delete ws.user;
//clear token_hash in db, etc
if(isLoggedIn(ws)) {
await pool.query(`update user_account set token_expiry = null, token_hash = null where id = $1`, [ws.user_ID]);
authenticated.delete(ws.user_ID);
delete ws.user_ID;
delete ws.user_type;
ws.send(JSON.stringify({
response_ID: request_ID
}));
ws.publish('user/authenticated', JSON.stringify({
what: 'user/authenticated',//tbd
how: 'update',
data: authenticated.size
}));
} else {
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'not logged in'
}));
}
//401 , 403
if(ws.user && ws.user.type === 'god') {
let result = (await pool.query('select * from user_account')).rows;
ws.send(JSON.stringify(result));
if(isLoggedIn(ws)) {
if(is(ws, 'god')) {
let users = (await pool.query('select * from user_account')).rows;//* is a bad idea... fix later
for(let i = 0; i < users.length; ++i) {
desensitize(users[i]);//shouldn't need this loop
}
ws.subscribe('user/#');//maybe for each subscribe call, call unsubscribeAll before (0.17.1 not released yet)?
//I suppose the only issue with over subscribe is waste of resources - and if user type changes
ws.send(JSON.stringify({
response_ID: request_ID,
data: users
}));
} else {
ws.send(JSON.stringify({
response_ID: request_ID,
data: 'forbidden'
}));
}
close: (ws, code, message) => {
close: async (ws, code, message) => {
if(isLoggedIn(ws)) {
await pool.query(`update user_account set token_expiry = now() + interval '14 day' where id = $1`, [ws.user_ID]);
authenticated.delete(ws.user_ID);
ws.publish('user/authenticated', JSON.stringify({
what: 'user/authenticated',//tbd
how: 'update',
data: authenticated.size
}));
}
--clients;
ws.publish('user/count', "" + clients);