Skip to content

Commit

Permalink
add: online presence, handle ban unban and join room in sockets (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
automerge-pingpong[bot] committed Nov 5, 2023
2 parents abf4178 + b392214 commit b5c141e
Show file tree
Hide file tree
Showing 22 changed files with 1,318 additions and 128 deletions.
4 changes: 3 additions & 1 deletion backend/code/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json

users.txt
74 changes: 74 additions & 0 deletions backend/code/accountPickerCli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as figlet from 'figlet';
import * as fs from 'fs';
import * as readline from 'node:readline';
(async () => {
const header = figlet.textSync('Account Picker', {
font: 'Roman',
horizontalLayout: 'default',
verticalLayout: 'default',
});

console.log(header);

const users = fs
.readFileSync('./users.txt', 'utf8')
.trim()
.split('\n')
.map((user) => {
const [email, password] = user.split(':');
return { email, password };
});

// list users to choose from
const userChoices = users.map((user, index) => {
return {
name: `${user.email} (${user.password})`,
value: index,
};
});

// list uset userChoices
//
for (const userChoice of userChoices) {
console.log(`${userChoice.value}: ${userChoice.name}`);
}

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const question = (query: string) =>
new Promise<string>((resolve) =>
rl.question(query, (ans) => {
resolve(ans);
}),
);

const userIndex = await question('User index: ');
const user = users[parseInt(userIndex as string, 10)];
console.log(`You chose: ${user.email} (${user.password})`);
rl.close();

const codeTemplate = `
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"email": "${user.email}",
"password": "${user.password}"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("http://localhost:3001/auth/login", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));`;
console.log(codeTemplate);
})();
Loading

0 comments on commit b5c141e

Please sign in to comment.