From d2328c00318766783408360c9e377b1a77d0e69a Mon Sep 17 00:00:00 2001 From: DaviMatheus Date: Sun, 4 Aug 2024 18:25:42 -0300 Subject: [PATCH] fixing_email_verification --- .env.dev | 1 + src/users/email.service.ts | 81 ++++++++++++++++++++++++++++++++++++-- src/users/users.service.ts | 4 +- 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/.env.dev b/.env.dev index 004c498..048404d 100644 --- a/.env.dev +++ b/.env.dev @@ -12,6 +12,7 @@ MICROSOFT_CLIENT_SECRET="" MICROSOFT_TENANT_ID="" MICROSOFT_CALLBACK_URL="" FRONTEND_URL="" +EMAIL_LINK="" # Estas etapas a baixo ainda nao sao necessarias # RABBIT_MQ_URI=amqp://admin:admin@rabbitmq:5672 diff --git a/src/users/email.service.ts b/src/users/email.service.ts index 6babdf6..1d46459 100644 --- a/src/users/email.service.ts +++ b/src/users/email.service.ts @@ -16,12 +16,87 @@ export class EmailService { ); } - async sendVerificationEmail(email: string, token: string): Promise { + async sendVerificationEmail(email: string): Promise { + const loginLink = process.env.EMAIL_LINK const mailOptions = { from: process.env.EMAIL_USER, to: email, - subject: 'Verificação de Conta', - text: `Seu token de verificação é: ${token}`, + subject: 'Bem-vindo!', + html: ` + + + + + +
+

Bem-vindo ao Nosso Serviço!

+

Olá,

+

Seu cadastro foi realizado com sucesso. Para acessar sua conta, clique no botão abaixo:

+
+ Acessar Conta +
+

Se você não se cadastrou em nosso serviço, por favor ignore este e-mail.

+ +
+ + + `, }; await this.transporter.sendMail(mailOptions); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 93cb6c6..3424eb6 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -31,7 +31,9 @@ export class UsersService { }); try { - return await createdUser.save(); + const user = await createdUser.save(); + await this.emailService.sendVerificationEmail(email); + return user; } catch (error) { if (error instanceof MongoError && error.code === 11000) { throw new ConflictException(