From d9e54bb83f86d429dc67233998bd642c40da8b62 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Sat, 21 Oct 2023 18:39:13 +0200 Subject: [PATCH] upd: send email on new pending approval --- .../src/server/api/SignupApiService.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/backend/src/server/api/SignupApiService.ts b/packages/backend/src/server/api/SignupApiService.ts index ce86a0776a32..ace91dc22f89 100644 --- a/packages/backend/src/server/api/SignupApiService.ts +++ b/packages/backend/src/server/api/SignupApiService.ts @@ -22,6 +22,7 @@ import { L_CHARS, secureRndstr } from '@/misc/secure-rndstr.js'; import { SigninService } from './SigninService.js'; import type { FastifyRequest, FastifyReply } from 'fastify'; import instance from './endpoints/charts/instance.js'; +import { RoleService } from '@/core/RoleService.js'; @Injectable() export class SignupApiService { @@ -51,6 +52,7 @@ export class SignupApiService { private signupService: SignupService, private signinService: SigninService, private emailService: EmailService, + private roleService: RoleService, ) { } @@ -229,6 +231,18 @@ export class SignupApiService { }); } + const moderators = await this.roleService.getModerators(); + + for (const moderator of moderators) { + const profile = await this.userProfilesRepository.findOneBy({ userId: moderator.id }); + + if (profile?.email) { + this.emailService.sendEmail(profile.email, 'New user awaiting approval', + `A new user called ${account.username} is awaiting approval with the following reason: "${reason}"`, + `A new user called ${account.username} is awaiting approval with the following reason: "${reason}"`); + } + } + reply.code(204); return; } else { @@ -308,6 +322,19 @@ export class SignupApiService { 'Congratulations! Your account is now pending approval. You will get notified when you have been accepted.', 'Congratulations! Your account is now pending approval. You will get notified when you have been accepted.'); } + + const moderators = await this.roleService.getModerators(); + + for (const moderator of moderators) { + const profile = await this.userProfilesRepository.findOneBy({ userId: moderator.id }); + + if (profile?.email) { + this.emailService.sendEmail(profile.email, 'New user awaiting approval', + `A new user called ${pendingUser.username} is awaiting approval with the following reason: "${pendingUser.reason}"`, + `A new user called ${pendingUser.username} is awaiting approval with the following reason: "${pendingUser.reason}"`); + } + } + return { pendingApproval: true }; }