diff options
author | Puyodead1 <puyodead@proton.me> | 2023-01-31 09:23:59 -0500 |
---|---|---|
committer | Puyodead1 <puyodead@protonmail.com> | 2023-02-23 22:52:24 -0500 |
commit | ada821070bf3fd9c18e57884264c8c6497b9eb9f (patch) | |
tree | e1f3e00e0a3a1514e333d404a2f3456732a91939 | |
parent | fix: email verification (diff) | |
download | server-ada821070bf3fd9c18e57884264c8c6497b9eb9f.tar.xz |
add right to resend verification emails
-rw-r--r-- | src/api/routes/auth/verify/resend.ts | 46 | ||||
-rw-r--r-- | src/util/config/types/RegisterConfiguration.ts | 2 | ||||
-rw-r--r-- | src/util/util/Rights.ts | 1 |
3 files changed, 27 insertions, 22 deletions
diff --git a/src/api/routes/auth/verify/resend.ts b/src/api/routes/auth/verify/resend.ts index a798a3d9..d54ddf73 100644 --- a/src/api/routes/auth/verify/resend.ts +++ b/src/api/routes/auth/verify/resend.ts @@ -22,28 +22,32 @@ import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; const router = Router(); -router.post("/", route({}), async (req: Request, res: Response) => { - const user = await User.findOneOrFail({ - where: { id: req.user_id }, - select: ["username", "email"], - }); +router.post( + "/", + route({ right: "RESEND_VERIFICATION_EMAIL" }), + async (req: Request, res: Response) => { + const user = await User.findOneOrFail({ + where: { id: req.user_id }, + select: ["username", "email"], + }); - if (!user.email) { - // TODO: whats the proper error response for this? - throw new HTTPError("User does not have an email address", 400); - } + if (!user.email) { + // TODO: whats the proper error response for this? + throw new HTTPError("User does not have an email address", 400); + } - await Email.sendVerificationEmail(user, user.email) - .then((info) => { - console.log("Message sent: %s", info.messageId); - return res.sendStatus(204); - }) - .catch((e) => { - console.error( - `Failed to send verification email to ${user.username}#${user.discriminator}: ${e}`, - ); - throw new HTTPError("Failed to send verification email", 500); - }); -}); + await Email.sendVerificationEmail(user, user.email) + .then((info) => { + console.log("Message sent: %s", info.messageId); + return res.sendStatus(204); + }) + .catch((e) => { + console.error( + `Failed to send verification email to ${user.username}#${user.discriminator}: ${e}`, + ); + throw new HTTPError("Failed to send verification email", 500); + }); + }, +); export default router; diff --git a/src/util/config/types/RegisterConfiguration.ts b/src/util/config/types/RegisterConfiguration.ts index 689baa85..b8db0077 100644 --- a/src/util/config/types/RegisterConfiguration.ts +++ b/src/util/config/types/RegisterConfiguration.ts @@ -35,5 +35,5 @@ export class RegisterConfiguration { allowMultipleAccounts: boolean = true; blockProxies: boolean = true; incrementingDiscriminators: boolean = false; // random otherwise - defaultRights: string = "312119568366592"; // See `npm run generate:rights` + defaultRights: string = "875069521787904"; // See `npm run generate:rights` } diff --git a/src/util/util/Rights.ts b/src/util/util/Rights.ts index b48477ed..383f07ec 100644 --- a/src/util/util/Rights.ts +++ b/src/util/util/Rights.ts @@ -93,6 +93,7 @@ export class Rights extends BitField { EDIT_FLAGS: BitFlag(46), // can set others' flags MANAGE_GROUPS: BitFlag(47), // can manage others' groups VIEW_SERVER_STATS: BitFlag(48), // added per @chrischrome's request — can view server stats) + RESEND_VERIFICATION_EMAIL: BitFlag(49), // can resend verification emails (/auth/verify/resend) }; any(permission: RightResolvable, checkOperator = true) { |