mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
feat(api): ✨ Implement password resets
This commit is contained in:
parent
1365987a1c
commit
24288c95b5
11 changed files with 1998 additions and 19 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue