Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Run all OpenHotel stack locally with Docker.
| asset-editor | `openhotel/asset-editor` | http://localhost:2030 |
| static | `openhotel/static` | http://localhost:1995 |
| s3 | SeaweedFS | http://localhost:9000 |
| mail | Mailpit | http://localhost:8025 |

## Requirements

Expand Down
18 changes: 18 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- "2030:2030" # asset-editor
- "1995:1995" # static
- "9000:9000" # s3
- "8025:8025" # mail

s3:
image: chrislusf/seaweedfs:latest
Expand All @@ -32,9 +33,26 @@ services:
- ./s3/config.json:/etc/seaweedfs/s3.json:ro
- s3-data:/data

mail:
image: axllent/mailpit:latest
container_name: mail
network_mode: service:net
depends_on: [net]
restart: unless-stopped
command: >-
--smtp-tls-cert sans:localhost
--smtp-tls-key sans:localhost
--smtp-require-tls
--smtp-auth-accept-any

auth:
<<: *dev
container_name: auth
depends_on:
net:
condition: service_started
mail:
condition: service_healthy
build:
context: .
args:
Expand Down
6 changes: 6 additions & 0 deletions configs/auth.yml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
version: development
email:
enabled: true
hostname: localhost
port: 1025
username: no-reply@openhotel.local
password: devkit
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tasks": {
"setup": "deno run --allow-read --allow-write --allow-run=git,docker setup.ts",
"seed": "deno run --allow-read --allow-write --allow-net=localhost:2024 seed.ts",
"seed": "deno run --allow-read --allow-write --allow-net=localhost:2024,localhost:8025 seed.ts",
"reset": "deno run --allow-read --allow-write --allow-run=docker reset.ts",
"up": "docker compose up -d --build",
"logs": "docker compose logs -f --tail=100",
Expand Down
40 changes: 39 additions & 1 deletion seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Integration = {
};

const AUTH_API = "http://localhost:2024/api/v3";
const MAIL_API = "http://localhost:8025/api/v1";
const FINGERPRINT = "devkit-seed";
const INTEGRATIONS: Record<string, Integration> = {
client: {
Expand Down Expand Up @@ -77,12 +78,49 @@ const register = async ({ username, email, password }: User) => {
else fail(`${username}: register failed (${status} ${message ?? ""})`);
};

const login = async ({ username, email, password }: User): Promise<Session> => {
const verifyEmail = async ({ username, email }: User) => {
for (let attempt = 0; attempt < 10; attempt++) {
const { messages } = await fetch(
`${MAIL_API}/search?query=${encodeURIComponent(`to:"${email}"`)}`,
).then((response) => response.json());

if (messages.length) {
const { HTML } = await fetch(
`${MAIL_API}/message/${messages[0].ID}`,
).then((response) => response.json());

const [, id, token] =
/verify\?id=([^&"'\s<]+)&(?:amp;)?token=([^&"'\s<]+)/.exec(HTML) ?? [];
if (!id || !token) break;

const { status } = await request(
"GET",
`/account/verify?id=${id}&token=${token}`,
);
if (status !== 200) break;

ok(`${username}: email verified`);
return;
}

await new Promise((resolve) => setTimeout(resolve, 500));
}

fail(`${username}: email could not be verified`);
};

const login = async (user: User, retry = true): Promise<Session> => {
const { username, email, password } = user;
const { status, data, message } = await request<{
accountId: string;
token: string;
}>("POST", "/account/login", { body: { email, password } });

if (retry && message === "Your email is not verified!") {
await verifyEmail(user);
return login(user, false);
}

if (status !== 200 || !data) {
return fail(`${username}: login failed (${status} ${message ?? ""})`);
}
Expand Down
Loading