feat(api): Implement password resets

This commit is contained in:
Jesse Wierzbinski 2024-05-16 22:27:41 -10:00
parent 1365987a1c
commit 24288c95b5
No known key found for this signature in database
11 changed files with 1998 additions and 19 deletions

View file

@ -4,6 +4,7 @@ import chalk from "chalk";
import { renderUnicodeCompact } from "uqr";
import { UserFinderCommand } from "~cli/classes";
import { formatArray } from "~cli/utils/format";
import { config } from "~packages/config-manager";
export default class UserReset extends UserFinderCommand<typeof UserReset> {
static override description = "Resets users' passwords";
@ -84,30 +85,41 @@ export default class UserReset extends UserFinderCommand<typeof UserReset> {
}
}
const link = "https://example.com/reset-password";
for (const user of users) {
const token = await user.resetPassword();
const link = new URL(
`${config.frontend.routes.password_reset}?${new URLSearchParams(
{
token,
},
).toString()}`,
config.http.base_url,
).toString();
!flags.raw &&
this.log(
`${chalk.green("✓")} Password reset for ${
users.length
} user(s)`,
);
!flags.raw &&
this.log(
`${chalk.green("✓")} Password reset for ${
users.length
} user(s)`,
flags.raw
? link
: `\nPassword reset link for ${chalk.bold(
"@testuser",
)}: ${chalk.underline(chalk.blue(link))}\n`,
);
this.log(
flags.raw
? link
: `\nPassword reset link for ${chalk.bold(
"@testuser",
)}: ${chalk.underline(chalk.blue(link))}\n`,
);
const qrcode = renderUnicodeCompact(link, {
border: 2,
});
const qrcode = renderUnicodeCompact(link, {
border: 2,
});
// Pad all lines of QR code with spaces
// Pad all lines of QR code with spaces
!flags.raw && this.log(` ${qrcode.replaceAll("\n", "\n ")}`);
!flags.raw && this.log(` ${qrcode.replaceAll("\n", "\n ")}`);
}
this.exit(0);
}