add right to resend verification emails
This commit is contained in:
parent
1aba7d591c
commit
ada821070b
@ -22,28 +22,32 @@ import { Request, Response, Router } from "express";
|
|||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", route({}), async (req: Request, res: Response) => {
|
router.post(
|
||||||
const user = await User.findOneOrFail({
|
"/",
|
||||||
where: { id: req.user_id },
|
route({ right: "RESEND_VERIFICATION_EMAIL" }),
|
||||||
select: ["username", "email"],
|
async (req: Request, res: Response) => {
|
||||||
});
|
const user = await User.findOneOrFail({
|
||||||
|
where: { id: req.user_id },
|
||||||
if (!user.email) {
|
select: ["username", "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);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -35,5 +35,5 @@ export class RegisterConfiguration {
|
|||||||
allowMultipleAccounts: boolean = true;
|
allowMultipleAccounts: boolean = true;
|
||||||
blockProxies: boolean = true;
|
blockProxies: boolean = true;
|
||||||
incrementingDiscriminators: boolean = false; // random otherwise
|
incrementingDiscriminators: boolean = false; // random otherwise
|
||||||
defaultRights: string = "312119568366592"; // See `npm run generate:rights`
|
defaultRights: string = "875069521787904"; // See `npm run generate:rights`
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@ export class Rights extends BitField {
|
|||||||
EDIT_FLAGS: BitFlag(46), // can set others' flags
|
EDIT_FLAGS: BitFlag(46), // can set others' flags
|
||||||
MANAGE_GROUPS: BitFlag(47), // can manage others' groups
|
MANAGE_GROUPS: BitFlag(47), // can manage others' groups
|
||||||
VIEW_SERVER_STATS: BitFlag(48), // added per @chrischrome's request — can view server stats)
|
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) {
|
any(permission: RightResolvable, checkOperator = true) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user