diff --git a/.env.example b/.env.example index e093d9c5c8753f..8444f809f5eadb 100644 --- a/.env.example +++ b/.env.example @@ -80,9 +80,15 @@ NEXTAUTH_COOKIE_DOMAIN= # Set this to '1' if you don't want Cal to collect anonymous usage CALCOM_TELEMETRY_DISABLED= -# FC Registration Token +# Account Registration Token (invoked by Drive) USER_CREATION_ACCESS_KEY= +# For Accessing FlashCampus Token (issued by FlashCampus / used by Cal.com to Encode) +FLASHCAMPUS_KEY= + +# Link for targeted Flash Campus +FLASHCAMPUS_LINK= + # ApiKey for cronjobs CRON_API_KEY='0cc0e6c35519bba620c9360cfe3e68d0' diff --git a/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts b/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts index 20351a9a7546b7..721c8291e3be25 100644 --- a/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts +++ b/packages/trpc/server/routers/loggedInViewer/updateProfile.handler.ts @@ -1,4 +1,6 @@ import { Prisma } from "@prisma/client"; +import axios from "axios"; +import jwt from "jsonwebtoken"; // eslint-disable-next-line no-restricted-imports import { keyBy } from "lodash"; import type { GetServerSidePropsContext, NextApiResponse } from "next"; @@ -370,6 +372,9 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) } } + //notify FlashCampus regarding update/activation + activateUserInFlashCampus({ ctx, input }); + return { ...input, email: emailVerification && !secondaryEmail?.emailVerified ? user.email : input.email, @@ -399,3 +404,38 @@ const handleUserMetadata = ({ ctx, input }: UpdateProfileOptions) => { // Required so we don't override and delete saved values return { ...userMetadata, ...cleanMetadata }; }; + +async function activateUserInFlashCampus({ ctx, input }: UpdateProfileOptions) { + const { user } = ctx; + + if (user.username != null) { + const email = user.email; + + const defaultLink = `${process.env.NEXT_PUBLIC_WEBAPP_URL}/${user.username}/15min_meeting`; + + const url = `${process.env.FLASHCAMPUS_LINK}/api/account/activate-mentor`; + + const tokenizedPayload = jwt.sign( + { + email, + default_link: defaultLink, + }, + process.env.FLASHCAMPUS_KEY as string, + { + expiresIn: 1800, // 30 min + } + ); + + const result = await axios.post( + url, + { payload: tokenizedPayload }, + { + headers: { + "Content-Type": "application/x-www-form-urlencoded;charset=utf-8", + }, + } + ); + + //todo: if the results are a failure (e.g on a server failure case), they should be logged. Or something. + } +} diff --git a/turbo.json b/turbo.json index 0c2a34bc6cf9bb..4b3e486abc050b 100644 --- a/turbo.json +++ b/turbo.json @@ -285,6 +285,8 @@ "EMAIL_SERVER_USER", "EMAIL_SERVER", "EXCHANGE_DEFAULT_EWS_URL", + "FLASHCAMPUS_KEY", + "FLASHCAMPUS_LINK", "FORMBRICKS_FEEDBACK_SURVEY_ID", "AVATARAPI_USERNAME", "AVATARAPI_PASSWORD",