-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1337 from haseebzaki-07/new_branch_subscribe
Add subscribe
- Loading branch information
Showing
10 changed files
with
176 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Custom Toastify styling */ | ||
.toastify { | ||
font-family: Arial, sans-serif; | ||
font-size: 16px; | ||
font-weight: 500; | ||
padding: 16px; | ||
border-radius: 8px; | ||
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15); | ||
text-align: center; | ||
} | ||
|
||
.toastify-success { | ||
background: linear-gradient(135deg, #4CAF50, #81C784); /* Green gradient */ | ||
color: #fff; | ||
} | ||
|
||
.toastify-error { | ||
background: linear-gradient(135deg, #FF3D00, #FF6E40); /* Red gradient */ | ||
color: #fff; | ||
} | ||
|
||
.toastify-close { | ||
color: #fff; | ||
font-weight: bold; | ||
font-size: 18px; | ||
line-height: 16px; | ||
} | ||
|
||
.toastify .toastify-content { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
/* Icon Styling */ | ||
.toastify .toastify-icon { | ||
margin-right: 10px; | ||
font-size: 20px; | ||
} |
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,51 @@ | ||
document.getElementById('newsletter-form').addEventListener('submit', async function(event) { | ||
event.preventDefault(); | ||
|
||
const email = document.getElementById('email').value; | ||
|
||
try { | ||
const response = await fetch('http://localhost:3000/subscribe', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ email }) | ||
}); | ||
|
||
if (response.ok) { | ||
// Show Toastify success notification | ||
Toastify({ | ||
text: "Subscription successful! A confirmation email has been sent.", | ||
duration: 3000, | ||
close: true, | ||
gravity: "top", | ||
position: "right", | ||
className: "toastify toastify-success", | ||
stopOnFocus: true, | ||
}).showToast(); | ||
|
||
document.getElementById('newsletter-form').reset(); | ||
} else { | ||
Toastify({ | ||
text: "Failed to subscribe. Please try again.", | ||
duration: 3000, | ||
close: true, | ||
gravity: "top", | ||
position: "right", | ||
className: "toastify toastify-error", | ||
stopOnFocus: true, | ||
}).showToast(); | ||
} | ||
} catch (error) { | ||
Toastify({ | ||
text: "Error occurred. Please check your connection and try again.", | ||
duration: 3000, | ||
close: true, | ||
gravity: "top", | ||
position: "right", | ||
className: "toastify toastify-error", | ||
stopOnFocus: true, | ||
}).showToast(); | ||
console.error('Error:', error); | ||
} | ||
}); |
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,2 @@ | ||
EMAIL_USER="your_email_user" | ||
EMAIL_PASS="email_password" |
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,39 @@ | ||
const nodemailer = require('nodemailer'); | ||
const dotenv = require('dotenv'); | ||
dotenv.config() | ||
|
||
|
||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
|
||
|
||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS | ||
} | ||
}); | ||
|
||
const subscribeUser = async (req, res) => { | ||
const { email } = req.body; | ||
|
||
try { | ||
|
||
const mailOptions = { | ||
from: process.env.EMAIL_USER, | ||
to: email, | ||
subject: 'Thank you for subscribing to Metaverse!', | ||
html: `<h3>Welcome to our Newsletter!</h3> | ||
<p>Thank you for subscribing to metavserse Stay tuned for the latest updates.</p>` | ||
}; | ||
|
||
|
||
await transporter.sendMail(mailOptions); | ||
|
||
res.status(201).json({ message: 'Subscription successful! A confirmation email has been sent.' }); | ||
} catch (error) { | ||
console.error('Error in subscribing user:', error); | ||
res.status(500).json({ message: 'Oops! Something went wrong. Please try again.' }); | ||
} | ||
}; | ||
|
||
module.exports = { subscribeUser }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"firebase": "^10.12.2" | ||
"firebase": "^10.12.2", | ||
"nodemailer": "^6.9.15" | ||
} | ||
} |