diff --git a/src/index.ts b/src/index.ts index 099d6b7b0a820189aa147b0b0017d137b16f245e..810bd7ff53de32fc75fefde4e4af1614b5d400ec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ import { publicCommentsReplyRoute, commentReplyRouter } from './routes/comment-r import { publicUserCollectionsRoutes, userCollectionsRoute } from './routes/user-collection.route' import { publicS3, s3Routes } from './routes/s3.route' import { homologationRouter } from './routes/homologation.route' +import { contactRoute } from './routes/contact.route' @@ -122,6 +123,7 @@ app .route('/replyComment', publicCommentsReplyRoute) .route('/userCollections', publicUserCollectionsRoutes) .route('/s3', publicS3) + .route('/contact', contactRoute) //rotas que precisam de token app .basePath('/api') diff --git a/src/routes/contact.route.ts b/src/routes/contact.route.ts new file mode 100644 index 0000000000000000000000000000000000000000..7905c506756f4d1ce1e3127778f5030746e2a66c --- /dev/null +++ b/src/routes/contact.route.ts @@ -0,0 +1,26 @@ +import { ContactService } from "@/services/contact.service"; +import { zValidator } from "@hono/zod-validator"; +import { Hono } from "hono"; +import Container from "typedi"; +import { z } from "zod"; + +const contactService = Container.get(ContactService) + +export const contactRoute = new Hono() + .post('/contact', + zValidator('json', z.object({ + name: z.string().min(1, 'Name is required'), + email: z.string().email(), + message: z.string().min(10, 'Message should be at least 10 characters long'), + })) + , async (c) => { + try { + const { name, email, message } = await c.req.json(); + + await contactService.sendContactEmail(email, message, name) + return c.json({ status: 'success', name, email, message }); + } catch (error) { + console.error('Error sending contact email:', error); + return c.json({ error: 'Invalid request data' }, 400); + } + }); \ No newline at end of file diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index 527e4361d7162411adba03a43c2291d7f07bb0ce..30d51df64e15d0ec469f22fd496f7d5895c5eb68 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -195,7 +195,6 @@ export class AuthService { html: text }); console.log("E-mail enviado:", response); - console.log(userEmail) } catch (error) { console.error("Erro ao enviar e-mail:", error); } diff --git a/src/services/contact.service.ts b/src/services/contact.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..6c7eccd740ca2ee1d925e0c15c3b5f6aff2f0a88 --- /dev/null +++ b/src/services/contact.service.ts @@ -0,0 +1,74 @@ +import { Service } from "typedi"; +import transporter from "@/mailer"; + +@Service() +export class ContactService { + async sendContactEmail(email: string, text: string, name: string) { + const message = ` + <head> + <style> + + .container { + display: block; + text-align: left; + background-color: rgb(240, 240, 240); + width: 90%; + margin: 0 auto; + padding: 30px 30px; + border-radius: 30%, + font-family: Arial, Helvetica, sans-serif; + } + + button { + background-color: #00bacc; + color: white; + border: none; + border-radius: 5px; + padding: 10px; + font-size: 16px; + cursor: pointer; + } + + .container_msg { + text-align: left; + padding: 0px 20px 0px 20px; + background-color: white; + } + + button:hover { + background-color: rgb(7, 29, 65, 0.8); + } + span { + color: #e74c3c; + font-weight: bold; + } + + </style> + </head> + + <body> + <div class="container" > + <a href="${process.env["URL"]}"></a> + <h1 style="color:#00bacc; font-size: 30px; font-weight: 800; margin-top: 5px; margin-bottom: 5px">Contato de ${name}</h1> + <br> + <p>${text}</p> + </div> + </body> + ` + + try { + const response = await transporter.sendMail({ + from: email, + to: "mecred@c3sl.ufpr.br", + subject: "Contato MECRED", + html: message + }); + console.log("E-mail enviado:", response); + console.log() + } catch (error) { + console.error("Erro ao enviar e-mail:", error); + } + } + + +} \ No newline at end of file