Füge E-Mail-Benachrichtigungen für Sperrungen und zeitlich begrenzte Sperrungen hinzu

This commit is contained in:
PxlLoewe
2025-06-28 00:13:55 -07:00
parent 1a1fab3f58
commit 96fcf7e4a5
12 changed files with 445 additions and 53 deletions

View File

@@ -56,6 +56,7 @@ import { setStandardName } from "../../../../../../helper/discord";
import { penaltyColumns } from "(app)/admin/penalty/columns";
import { addPenalty, editPenaltys } from "(app)/admin/penalty/actions";
import { reportColumns } from "(app)/admin/report/columns";
import { sendMail, sendMailByTemplate } from "../../../../../../helper/mail";
interface ProfileFormProps {
user: User;
@@ -349,6 +350,12 @@ export const UserPenalties = ({ user }: { user: User }) => {
userId: user.id,
createdUserId: createdUser.id,
});
if (user.email) {
await sendMailByTemplate(user.email, "timeban-notice", {
user,
staffName: createdUser.firstname + " " + createdUser.lastname,
});
}
penaltyTable.current?.refresh();
toast.success("Time-Ban wurde hinzugefügt!");
}}
@@ -370,6 +377,12 @@ export const UserPenalties = ({ user }: { user: User }) => {
userId: user.id,
createdUserId: createdUser.id,
});
if (user.email) {
await sendMailByTemplate(user.email, "ban-notice", {
user,
staffName: createdUser.firstname + " " + createdUser.lastname,
});
}
await editUser(user.id, { isBanned: true });
penaltyTable.current?.refresh();
toast.success("Ban wurde hinzugefügt!");

View File

@@ -58,42 +58,6 @@ export const deleteUser = async (id: string) => {
});
};
export const checkEmailCode = async (code: string) => {
const users = await prisma.user.findMany({
where: {
emailVerificationToken: code,
},
select: {
id: true,
emailVerificationToken: true,
emailVerificationExpiresAt: true,
},
});
const user = users[0];
if (!user || !user.emailVerificationExpiresAt) {
return { error: "Code ist ungültig" };
}
if (user.emailVerificationExpiresAt < new Date()) {
return { error: "Code ist nicht mehr gültig" };
}
await prisma.user.update({
where: {
id: user.id,
},
data: {
emailVerified: true,
emailVerificationToken: null,
emailVerificationExpiresAt: null,
},
});
return {
message: "Email bestätigt!",
};
};
export const sendVerificationLink = async (userId: string) => {
const code = Math.floor(10000 + Math.random() * 90000).toString();