diff --git a/pages/register/index.vue b/pages/register/index.vue index c32674c..ff7ff7e 100644 --- a/pages/register/index.vue +++ b/pages/register/index.vue @@ -12,7 +12,7 @@ > <ClientOnly> <Vueform - endpoint="/api/test" + endpoint="/api/user/create" method="POST" view="tabs" :model-value="form" diff --git a/server/api/test/code.ts b/server/api/test/code.ts index 2d0f25e..398d004 100644 --- a/server/api/test/code.ts +++ b/server/api/test/code.ts @@ -10,6 +10,8 @@ export default defineEventHandler(async (event) => { deadline: "desc", // 'asc' 表示升序,'desc' 表示降序 }, })) || { + phone: "", + code: "", deadline: new Date(), }; const deadlineDate = new Date(register.deadline); diff --git a/server/api/user/create.ts b/server/api/user/create.ts new file mode 100644 index 0000000..33eb423 --- /dev/null +++ b/server/api/user/create.ts @@ -0,0 +1,16 @@ +import { PrismaClient } from "@prisma/client"; +const db = new PrismaClient(); +export default defineEventHandler(async (event) => { + const body = await readBody(event); + await db.user.create({ + data: { + username: body.username, + phone: body.phone, + password: (await import("crypto")) + .createHash("md5") + .update(body.password) + .digest("hex"), + }, + }); + return 1; +});