feature: rooms and events implemented on the backend
This commit is contained in:
parent
df00324e24
commit
85024c6e62
29 changed files with 1659 additions and 115 deletions
|
@ -1,5 +1,8 @@
|
|||
import { SERVER, SERVER_OPTIONS } from 'jsr:@andyburke/serverus/server';
|
||||
import { convert_to_words } from 'jsr:@andyburke/lurid/word_bytes';
|
||||
import { API_CLIENT } from '../utils/api.ts';
|
||||
import { Cookie, getSetCookies } from '@std/http/cookie';
|
||||
import { generateTotp } from '@stdext/crypto/totp';
|
||||
|
||||
const TLDs: string[] = [
|
||||
'com',
|
||||
|
@ -94,3 +97,63 @@ export async function get_ephemeral_listen_server(options?: SERVER_OPTIONS): Pro
|
|||
|
||||
return ephemeral_server;
|
||||
}
|
||||
|
||||
type NEW_USER_INFO = {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
export async function get_new_user(client: API_CLIENT, user_info?: Record<string, any>): Promise<Record<string, any>> {
|
||||
const info: Record<string, any> = {
|
||||
username: random_username(),
|
||||
password: `${random_username()} ! ${random_username()}`,
|
||||
...user_info
|
||||
};
|
||||
|
||||
await client.fetch('/users', {
|
||||
method: 'POST',
|
||||
json: info
|
||||
});
|
||||
|
||||
const cookies: Cookie[] = [];
|
||||
const auth_response: any = await client.fetch('/auth', {
|
||||
method: 'POST',
|
||||
json: info,
|
||||
done: (response) => {
|
||||
cookies.push(...getSetCookies(response.headers));
|
||||
}
|
||||
});
|
||||
|
||||
info.user = auth_response.user;
|
||||
info.session = auth_response.session;
|
||||
|
||||
cookies.push({
|
||||
name: 'totp',
|
||||
value: await generateTotp(info.session?.secret),
|
||||
maxAge: 30,
|
||||
expires: Date.now() + 30_000,
|
||||
path: '/'
|
||||
});
|
||||
|
||||
info.headers_for_get = new Headers();
|
||||
for (const cookie of cookies) {
|
||||
info.headers_for_get.append(`x-${cookie.name}`, cookie.value);
|
||||
}
|
||||
info.headers_for_get.append('cookie', cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; '));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
export async function set_user_permissions(client: API_CLIENT, user: any, session: any, permissions: string[]): Promise<any> {
|
||||
return await client.fetch(`/users/${user.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'x-session_id': session.id,
|
||||
'x-totp': await generateTotp(session.secret),
|
||||
'x-test-override': 'true'
|
||||
},
|
||||
json: {
|
||||
permissions
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue