-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
489 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Suscribe from "../models/subscribe.js"; | ||
import { sendMailToSubscriber } from "../utils/sendMailToSubscribe.js"; | ||
export async function saveSubsribe(req, res) { | ||
try { | ||
const { name, email } = req.body; | ||
|
||
if (!name || !email) { | ||
return res.status(400).json({ message: "All fields are required." }); | ||
} | ||
|
||
// Create new contact document | ||
const newSuscribe = new Suscribe({ name, email }); | ||
sendMailToSubscriber(newSuscribe) | ||
await newSuscribe.save(); | ||
res | ||
.status(201) | ||
.json({ message: "Contact form submitted successfully!", newSuscribe }); | ||
} catch (error) { | ||
console.error("Error saving contact form:", error); | ||
res.status(500).json({ message: "Failed to submit contact form.", error }); | ||
} | ||
} | ||
|
||
export async function getSubscribe(req, res) { | ||
res.send('hello subscriber') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const subscribeSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
match: [/^\S+@\S+\.\S+$/, "Please enter a valid email address"] | ||
}, | ||
subscribedAt: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
const Subscribe = mongoose.model("Subscribe", subscribeSchema); | ||
|
||
export default Subscribe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from "express"; | ||
const router = express.Router(); | ||
import { getSubscribe, saveSubsribe } from "../controllers/subscribeController.js"; | ||
|
||
router.post("/subscribe", saveSubsribe); | ||
router.get("/getSubscribe", getSubscribe); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import nodemailer from 'nodemailer'; | ||
import dotenv from 'dotenv'; | ||
|
||
// Load environment variables from .env file | ||
dotenv.config(); | ||
|
||
const sendMailToAdmin = (userdata) => { | ||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
host: "smtp.gmail.com", | ||
port: 587, | ||
secure: false, | ||
auth: { | ||
user: process.env.EMAIL_ID, // by this email id you will get mail | ||
pass: process.env.PASS_KEY, // passkey | ||
}, | ||
}); | ||
|
||
async function main() { | ||
await transporter.sendMail({ | ||
from: { | ||
name: `Wordwise - ${new Date().toLocaleString()}`, | ||
address: process.env.EMAIL_ID, | ||
}, // sender address | ||
to: process.env.ADMIN_EMAIL_ID, // list of receivers | ||
subject: "New User Feedback from Wordwise ✔", // Subject line | ||
text: "Wordwise User Feedback", // plain text body | ||
html: `<div style="background: black; color: white; height: 100vh; padding: 20px;"> | ||
<div class="heading" style="font-size: 2rem; text-align: center; margin-bottom: 20px;"> | ||
Wordwise User Feedback | ||
</div> | ||
<table style="width: 50%; border-collapse: collapse; margin: 0 auto;"> | ||
<thead> | ||
<tr> | ||
<th style="border: 1px solid white; padding: 10px; text-align:center; background-color: #0076b4;"> | ||
Field | ||
</th> | ||
<th style="border: 1px solid white; padding: 10px; text-align:center; background-color: #0076b4;"> | ||
Value | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Submitted At</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${new Date(userdata.submittedAt).toLocaleString()}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Overall Experience</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.overallExperience}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Recommendation</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.recommendation}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Additional Comments</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.additionalComments}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Improvement</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.improvement}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Most Helpful Feature</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.mostHelpfulFeature}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">New Features</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.newFeatures}</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">Features Used</td> | ||
<td style="border: 1px solid white; padding: 10px; text-align:center;">${userdata.featuresUsed.join(', ')}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div>`, // html body | ||
}); | ||
} | ||
|
||
main().catch(console.error); | ||
} | ||
|
||
export { sendMailToAdmin }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import nodemailer from 'nodemailer'; | ||
import dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
const sendMailToSubscriber = (userdata) => { | ||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
host: "smtp.gmail.com", | ||
port: 587, | ||
secure: false, | ||
auth: { | ||
user: process.env.EMAIL_ID, | ||
pass: process.env.PASS_KEY, | ||
}, | ||
}); | ||
|
||
async function main() { | ||
await transporter.sendMail({ | ||
from: { | ||
name: "WordWise", | ||
address: process.env.EMAIL_ID, | ||
}, | ||
to: userdata.email, | ||
subject: "Welcome to WordWise! 📖 Your Vocabulary Journey Begins Here", | ||
text: "Thank you for subscribing to WordWise!", | ||
html: ` | ||
<div style="background-color: #f9f9fb; padding: 40px; font-family: Arial, sans-serif; color: #333;"> | ||
<div style="max-width: 600px; margin: 0 auto; background-color: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);"> | ||
<h2 style="font-size: 28px; color: #008080; text-align: center; margin-bottom: 20px;">Welcome to WordWise, ${userdata.name}!</h2> | ||
<p style="font-size: 16px; line-height: 1.7; color: #555; margin-bottom: 20px;"> | ||
We’re thrilled to have you join the WordWise community—a place where words come alive, and every blog post is crafted to expand your vocabulary and deepen your understanding of language and topics you care about. | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.7; color: #555; margin-bottom: 20px;"> | ||
At WordWise, we believe in the power of words to enlighten and inspire. Our responsive, user-friendly platform is designed with you in mind, ensuring that each visit feels as seamless as it is engaging. Whether you’re here to explore our latest blogs, delve into specific topics, or simply enjoy a well-crafted read, WordWise has something for everyone. | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.7; color: #555; margin-bottom: 20px;"> | ||
As part of our community, you’ll be among the first to receive fresh content that’s both insightful and enriching. From curated articles that explore a variety of subjects to interactive features that enhance your reading experience, WordWise is more than just a blog—it’s a journey into the world of words. | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.7; color: #555; margin-bottom: 20px;"> | ||
We encourage you to dive into our sections, such as Home, Leading Blogs, About, and Contact Us. Each one is thoughtfully designed to guide you through your reading adventure. And if you ever wish to share feedback or connect with us, our Contact Us page is always open. | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.7; color: #555; margin-bottom: 20px;"> | ||
Thank you for subscribing to WordWise! We’re excited to share our latest blogs and updates with you. Here’s to many engaging reads and enriching experiences ahead! | ||
</p> | ||
<p style="font-size: 16px; line-height: 1.7; color: #555; text-align: center; margin-top: 30px;"> | ||
With warm regards,<br/> | ||
<strong>The WordWise Team</strong> | ||
</p> | ||
</div> | ||
</div> | ||
`, | ||
}); | ||
} | ||
|
||
main().catch(console.error); | ||
}; | ||
|
||
export { sendMailToSubscriber }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.