iceshrimp-legacy/packages/backend/src/server/api/private/signup-pending.ts

39 lines
855 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import type Koa from "koa";
import { Users, UserPendings, UserProfiles } from "@/models/index.js";
import { signup } from "../common/signup.js";
import signin from "../common/signin.js";
export default async (ctx: Koa.Context) => {
const body = ctx.request.body;
2023-01-13 05:40:33 +01:00
const code = body["code"];
try {
const pendingUser = await UserPendings.findOneByOrFail({ code });
const { account, secret } = await signup({
username: pendingUser.username,
passwordHash: pendingUser.password,
});
UserPendings.delete({
id: pendingUser.id,
});
const profile = await UserProfiles.findOneByOrFail({ userId: account.id });
2023-01-13 05:40:33 +01:00
await UserProfiles.update(
{ userId: profile.userId },
{
email: pendingUser.email,
emailVerified: true,
emailVerifyCode: null,
},
);
signin(ctx, account);
} catch (e) {
ctx.throw(400, e);
}
};