From 0a2335ff7567bcd73fea669fc5c7d49b0f0f3a3c Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Wed, 26 Apr 2023 19:44:38 -0700 Subject: [PATCH] feat: :sparkles: frontend interface for post-account creation email verification --- .../src/server/api/private/verify-email.ts | 40 +++++++++++++++++++ packages/backend/src/server/index.ts | 34 ---------------- packages/client/src/pages/signup-complete.vue | 2 - packages/client/src/pages/verify-email.vue | 35 ++++++++++++++++ packages/client/src/router.ts | 4 ++ 5 files changed, 79 insertions(+), 36 deletions(-) create mode 100644 packages/backend/src/server/api/private/verify-email.ts create mode 100644 packages/client/src/pages/verify-email.vue diff --git a/packages/backend/src/server/api/private/verify-email.ts b/packages/backend/src/server/api/private/verify-email.ts new file mode 100644 index 0000000000..a5cc8d0a00 --- /dev/null +++ b/packages/backend/src/server/api/private/verify-email.ts @@ -0,0 +1,40 @@ +import type Koa from "koa"; +import { Users, UserProfiles } from "@/models/index.js"; +import { publishMainStream } from "@/services/stream.js"; + +export default async (ctx: Koa.Context) => { + const body = ctx.request.body; + + const code = body["code"]; + + const profile = await UserProfiles.findOneBy({ + emailVerifyCode: ctx.params.code, + }); + + if (profile != null) { + ctx.body = "Verify succeeded!"; + + await UserProfiles.update( + { userId: profile.userId }, + { + emailVerified: true, + emailVerifyCode: null, + }, + ); + + publishMainStream( + profile.userId, + "meUpdated", + await Users.pack( + profile.userId, + { id: profile.userId }, + { + detail: true, + includeSecrets: true, + }, + ), + ); + } else { + ctx.throw(404); + } +}; diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index 7d274f7d28..cd1425d6a2 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -127,40 +127,6 @@ router.get("/identicon/:x", async (ctx) => { ctx.body = fs.createReadStream(temp).on("close", () => cleanup()); }); -router.get("/verify-email/:code", async (ctx) => { - const profile = await UserProfiles.findOneBy({ - emailVerifyCode: ctx.params.code, - }); - - if (profile != null) { - ctx.body = "Verify succeeded!"; - ctx.status = 200; - - await UserProfiles.update( - { userId: profile.userId }, - { - emailVerified: true, - emailVerifyCode: null, - }, - ); - - publishMainStream( - profile.userId, - "meUpdated", - await Users.pack( - profile.userId, - { id: profile.userId }, - { - detail: true, - includeSecrets: true, - }, - ), - ); - } else { - ctx.status = 404; - } -}); - mastoRouter.get("/oauth/authorize", async (ctx) => { const { client_id, state, redirect_uri } = ctx.request.query; console.log(ctx.request.req); diff --git a/packages/client/src/pages/signup-complete.vue b/packages/client/src/pages/signup-complete.vue index db06799ba6..deb1f78461 100644 --- a/packages/client/src/pages/signup-complete.vue +++ b/packages/client/src/pages/signup-complete.vue @@ -35,5 +35,3 @@ definePageMetadata({ icon: "ph-user ph-bold ph-lg", }); - - diff --git a/packages/client/src/pages/verify-email.vue b/packages/client/src/pages/verify-email.vue new file mode 100644 index 0000000000..43923cb1e8 --- /dev/null +++ b/packages/client/src/pages/verify-email.vue @@ -0,0 +1,35 @@ + + + diff --git a/packages/client/src/router.ts b/packages/client/src/router.ts index a76c322bf1..16a056de9e 100644 --- a/packages/client/src/router.ts +++ b/packages/client/src/router.ts @@ -283,6 +283,10 @@ export const routes = [ path: "/signup-complete/:code", component: page(() => import("./pages/signup-complete.vue")), }, + { + path: "/verify-email/:code", + component: page(() => import("./pages/verify-email.vue")), + }, { path: "/announcements", component: page(() => import("./pages/announcements.vue")),