## What does this PR do? Loom: https://www.loom.com/share/361ca6ca9b5748079cba59ed2f348d90 Not all items on edit from update the user. This is very temp page to help Milos How to test: Login as admin user settings > admin > users search - see filtered users scroll to bottom of list - notice we refetch before you hit the bottom so you dont notice items loading delete user -> user is deleted and removed from list (radix bug in main causes dialog to freeze refresh to make this go away) edit user -> Edit users email/username/identityprovider. Not all items on this update work just yet. These will be picked up when we come to implement the proper user table.
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import dayjs from "@calcom/dayjs";
|
|
import { sendPasswordResetEmail } from "@calcom/emails";
|
|
import { PASSWORD_RESET_EXPIRY_HOURS } from "@calcom/emails/templates/forgot-password-email";
|
|
import { getTranslation } from "@calcom/lib/server/i18n";
|
|
import { prisma } from "@calcom/prisma";
|
|
|
|
import type { TrpcSessionUser } from "../../../trpc";
|
|
import type { TAdminPasswordResetSchema } from "./sendPasswordReset.schema";
|
|
|
|
type GetOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TAdminPasswordResetSchema;
|
|
};
|
|
|
|
export const sendPasswordResetHandler = async ({ ctx, input }: GetOptions) => {
|
|
const { userId } = input;
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
select: {
|
|
name: true,
|
|
email: true,
|
|
locale: true,
|
|
},
|
|
});
|
|
|
|
if (!user) {
|
|
throw new Error("User not found");
|
|
}
|
|
|
|
const t = await getTranslation(user.locale ?? "en", "common");
|
|
|
|
const expiry = dayjs().add(PASSWORD_RESET_EXPIRY_HOURS, "hours").toDate();
|
|
|
|
const passwordResetToken = await prisma.resetPasswordRequest.create({
|
|
data: {
|
|
email: user.email,
|
|
expires: expiry,
|
|
},
|
|
});
|
|
|
|
const resetLink = `${process.env.NEXT_PUBLIC_WEBAPP_URL}/auth/forgot-password/${passwordResetToken.id}`;
|
|
await sendPasswordResetEmail({
|
|
language: t,
|
|
user: {
|
|
name: user.name,
|
|
email: user.email,
|
|
},
|
|
resetLink,
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
};
|
|
};
|