Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/main/java/br/com/acta/common/client/BrevoClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package br.com.acta.common.client;

import br.com.acta.common.handler.exception.BusinessRuleException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import org.springframework.web.util.HtmlUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Component
public class BrevoClient {
private static final RestClient REST_CLIENT = RestClient.create();

@Value("${BREVO_API_KEY:}")
private String apiKey;

@Value("${BREVO_SENDER_EMAIL:}")
private String senderEmail;

@Value("${EXTERNAL_URL:http://localhost:8080}")
private String url;

public void enviarConvite(String email, String nome, OffsetDateTime expiraEm, String token) {
String html = carregarTemplate()
.replace("{{nome}}", HtmlUtils.htmlEscape(nome))
.replace("{{expiraEm}}", expiraEm.format(DateTimeFormatter.ofPattern("dd/MM/yyyy 'às' HH:mm")))
.replace("{{logoUrl}}", HtmlUtils.htmlEscape(url.replaceAll("/+$", "") + "/images/acta-logo.png"))
.replace("{{codigo}}", HtmlUtils.htmlEscape(token));

enviarEmail(email, html);
}

private void enviarEmail(String email, String html) {
Map<String, Object> mensagem = montarMensagem(email, html);

try {
REST_CLIENT.post()
.uri("https://api.brevo.com/v3/smtp/email").contentType(MediaType.APPLICATION_JSON)
.header("api-key", apiKey)
.body(mensagem).retrieve().toBodilessEntity();
} catch (RestClientException rce) {
throw new BusinessRuleException("Não foi possível enviar o convite por e-mail");
}
}

private Map<String, Object> montarMensagem(String email, String html) {
return Map.of(
"sender", Map.of("name", "ACTA", "email", senderEmail),
"to", List.of(Map.of("email", email)),
"subject", "Convite para acessar o ACTA",
"htmlContent", html
);
}

private String carregarTemplate() {
try (InputStream input = new ClassPathResource("templates/email/" + "convite-usuario.html").getInputStream()) {
return new String(input.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException ioe) {
throw new BusinessRuleException("Não foi possível carregar o e-mail de convite");
}
}
}
Binary file added src/main/resources/static/images/acta-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
301 changes: 301 additions & 0 deletions src/main/resources/templates/email/convite-usuario.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Convite para acessar o ACTA</title>
<style>
body, table, td, a {
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}

table, td {
mso-table-lspace: 0pt;
mso-table-rspace: 0pt;
}

body {
margin: 0;
padding: 0;
width: 100% !important;
min-width: 100%;
background-color: #eef7f8;
color: #081524;
font-family: Arial, Helvetica, sans-serif;
}

a {
color: #025A8A;
text-decoration: none;
}

.wrapper {
width: 100%;
background-color: #eef7f8;
padding: 32px 12px;
}

.container {
width: 100%;
max-width: 640px;
margin: 0 auto;
background-color: #ffffff;
border-radius: 18px;
overflow: hidden;
border: 1px solid #d5ebee;
box-shadow: 0 18px 45px rgba(8, 21, 36, 0.12);
}

.header {
background-color: #081524;
background-image: linear-gradient(135deg, #081524 0%, #025A8A 54%, #0AC2CA 100%);
padding: 34px 34px 32px;
}

.logo-shell {
width: 74px;
height: 74px;
border-radius: 18px;
background-color: rgba(255, 255, 255, 0.12);
border: 1px solid rgba(255, 255, 255, 0.22);
text-align: center;
}

.brand {
padding-left: 16px;
color: #ffffff;
}

.brand-name {
margin: 0;
font-size: 30px;
line-height: 34px;
font-weight: 800;
letter-spacing: 0;
}

.brand-subtitle {
margin: 4px 0 0;
font-size: 13px;
line-height: 18px;
color: #d9fbfc;
}

.hero-title {
margin: 30px 0 0;
color: #ffffff;
font-size: 29px;
line-height: 37px;
font-weight: 800;
letter-spacing: 0;
}

.hero-copy {
margin: 10px 0 0;
color: #e8fbfc;
font-size: 16px;
line-height: 24px;
}

.content {
padding: 34px;
}

.hello {
margin: 0 0 16px;
color: #081524;
font-size: 20px;
line-height: 28px;
font-weight: 700;
}

.paragraph {
margin: 0 0 18px;
color: #35485b;
font-size: 15px;
line-height: 24px;
}

.panel {
margin: 26px 0;
border-radius: 14px;
background-color: #effafa;
border: 1px solid #bcecef;
padding: 18px 20px;
}

.panel-label {
margin: 0 0 4px;
color: #027373;
font-size: 12px;
line-height: 18px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.06em;
}

.panel-value {
margin: 0;
color: #081524;
font-size: 15px;
line-height: 23px;
font-weight: 700;
}

.button-wrap {
padding: 8px 0 28px;
text-align: center;
}

.button {
display: inline-block;
background-color: #025A8A;
color: #ffffff !important;
border-radius: 10px;
padding: 15px 24px;
font-size: 15px;
line-height: 20px;
font-weight: 700;
text-align: center;
box-shadow: 0 10px 22px rgba(2, 90, 138, 0.25);
}

.button:hover {
background-color: #027373;
}

.fallback {
margin: 0;
color: #5f7182;
font-size: 13px;
line-height: 21px;
}

.fallback-link {
display: block;
margin-top: 8px;
color: #027373;
word-break: break-all;
}

.divider {
height: 4px;
line-height: 4px;
background-color: #0AC2CA;
}

.footer {
background-color: #f7fbfb;
border-top: 1px solid #deeff1;
padding: 22px 34px 28px;
}

.footer-text {
margin: 0;
color: #667789;
font-size: 12px;
line-height: 19px;
}

@media screen and (max-width: 520px) {
.wrapper {
padding: 0;
}

.container {
border-radius: 0;
border-left: 0;
border-right: 0;
}

.header, .content, .footer {
padding-left: 22px !important;
padding-right: 22px !important;
}

.hero-title {
font-size: 24px !important;
line-height: 31px !important;
}

.brand-name {
font-size: 24px !important;
}
}
</style>
</head>
<body>
<center class="wrapper">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center">
<table role="presentation" class="container" width="640" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="header">
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="middle" align="center" class="logo-shell">
<img src="{{logoUrl}}" width="52" height="52" alt="ACTA" style="display: block; margin: 0 auto; border: 0;">
</td>
<td valign="middle" class="brand">
<p class="brand-name">ACTA</p>
<p class="brand-subtitle">Transformando planejamento em resultado.</p>
</td>
</tr>
</table>

<h1 class="hero-title">Você foi convidado para acessar o ACTA</h1>
<p class="hero-copy">
Sua conta foi pré-cadastrada por um administrador. Ative o acesso para acompanhar ciclos,
tarefas, planos de ação e melhorias da sua empresa.
</p>
</td>
</tr>

<tr>
<td class="divider">&nbsp;</td>
</tr>

<tr>
<td class="content">
<p class="hello">Olá, {{nome}}.</p>
<p class="paragraph">
Você recebeu um convite para entrar no ACTA, a plataforma que organiza o PDCA desde a
identificação do problema até a verificação dos resultados.
</p>
<p class="paragraph">
Crie sua conta no app ACTA com este mesmo e-mail, confirme o endereço e informe o código abaixo para ativar seu acesso.
</p>

<div class="panel">
<p class="panel-label">Validade do convite</p>
<p class="panel-value">Este código expira em {{expiraEm}}.</p>
</div>

<div class="panel">
<p class="panel-label">Código de convite</p>
<p class="panel-value" style="font-family: monospace; font-size: 22px; letter-spacing: 0.12em; text-align: center;">{{codigo}}</p>
</div>
</td>
</tr>

<tr>
<td class="footer">
<p class="footer-text">
Se você não esperava este convite, ignore este e-mail. Nenhuma conta será ativada sem
o código de convite e a confirmação do e-mail da conta no Firebase.
</p>
<p class="footer-text" style="margin-top: 12px;">
ACTA - Plataforma de gestão PDCA.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>
Loading