completed user admin page
This commit is contained in:
35
apps/hub/app/(app)/admin/user/action.ts
Normal file
35
apps/hub/app/(app)/admin/user/action.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
"use server";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { prisma, Prisma } from "@repo/db";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { sendMailByTemplate } from "../../../../helper/mail";
|
||||
|
||||
export const editUser = async (id: string, data: Prisma.UserUpdateInput) => {
|
||||
return await prisma.user.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
export const resetPassword = async (id: string) => {
|
||||
const password = Math.random().toString(36).slice(-8);
|
||||
const hashedPassword = await bcrypt.hash(password, 15);
|
||||
|
||||
const user = await prisma.user.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
password: hashedPassword,
|
||||
},
|
||||
});
|
||||
|
||||
await sendMailByTemplate(user.email, "password-change", {
|
||||
user: user,
|
||||
password: password,
|
||||
});
|
||||
|
||||
return { password };
|
||||
};
|
||||
Reference in New Issue
Block a user