Skip to content

Commit

Permalink
fixing_email_verification
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviMatheus committed Aug 4, 2024
1 parent e51926a commit d2328c0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 78 additions & 3 deletions src/users/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,87 @@ export class EmailService {
);
}

async sendVerificationEmail(email: string, token: string): Promise<void> {
async sendVerificationEmail(email: string): Promise<void> {
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: `
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
font-size: 24px;
margin-top: 0;
}
p {
line-height: 1.6;
margin: 0 0 10px;
}
.button {
display: inline-block;
padding: 10px 20px;
font-size: 16px;
color: #fff !important; /* Ensures text color is white */
background-color: #f97316 !important; /* Tailwind's orange-500 color */
text-decoration: none !important;
border-radius: 9999px !important; /* Tailwind's rounded-full */
margin-top: 20px;
text-align: center;
font-weight: bold !important;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important; /* Tailwind's shadow-md */
transition: box-shadow 0.3s ease !important; /* Tailwind's transition duration */
}
.button:hover {
box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2) !important; /* Tailwind's shadow-lg */
}
.footer {
margin-top: 20px;
font-size: 12px;
color: #888;
text-align: center;
}
.footer a {
color: #007bff;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Bem-vindo ao Nosso Serviço!</h1>
<p>Olá,</p>
<p>Seu cadastro foi realizado com sucesso. Para acessar sua conta, clique no botão abaixo:</p>
<div style="text-align: center;">
<a href="${loginLink}" class="button">Acessar Conta</a>
</div>
<p>Se você não se cadastrou em nosso serviço, por favor ignore este e-mail.</p>
<div class="footer">
<p>Obrigado por se cadastrar!</p>
<p>Equipe de Suporte</p>
<p><a href="${loginLink}">${loginLink}</a></p>
</div>
</div>
</body>
</html>
`,
};

await this.transporter.sendMail(mailOptions);
Expand Down
4 changes: 3 additions & 1 deletion src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d2328c0

Please sign in to comment.