Skip to content

Commit

Permalink
Lesson 21
Browse files Browse the repository at this point in the history
  • Loading branch information
ArinSoftware committed May 11, 2021
1 parent a99d283 commit 1a4efef
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 203 deletions.
51 changes: 51 additions & 0 deletions controllers/pageController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const nodemailer = require("nodemailer");


exports.getIndexPage = (req, res) => {
console.log(req.session.userID);
res.status(200).render('index', {
Expand All @@ -22,3 +25,51 @@ exports.getLoginPage = (req, res) => {
page_name: 'login',
});
};

exports.getContactPage = (req, res) => {
res.status(200).render('contact', {
page_name: 'contact',
});
};

exports.sendEmail = async (req, res) => {

const outputMessage = `
<h1>Mail Details </h1>
<ul>
<li>Name: ${req.body.name}</li>
<li>Email: ${req.body.email}</li>
</ul>
<h1>Message</h1>
<p>${req.body.message}</p>
`

let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: "arinyazilim@gmail.com", // gmail account
pass: "bpwrtssmqdsdjdjw", // gmail password
},
});

// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Smart EDU Contact Form" <arinyazilim@gmail.com>', // sender address
to: "gcekic@gmail.com", // list of receivers
subject: "Smart EDU Contact Form New Message ✔", // Subject line
html: outputMessage, // html body
});

console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...

res.status(200).redirect('contact');

};
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"express": "^4.17.1",
"express-session": "^1.17.1",
"mongoose": "^5.12.7",
"nodemailer": "^6.6.0",
"slugify": "^1.5.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions routes/pageRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ router.route('/').get(pageController.getIndexPage);
router.route('/about').get(pageController.getAboutPage);
router.route('/register').get(redirectMiddleware, pageController.getRegisterPage);
router.route('/login').get(redirectMiddleware, pageController.getLoginPage);
router.route('/contact').get(pageController.getContactPage);
router.route('/contact').post(pageController.sendEmail);

module.exports = router;

47 changes: 47 additions & 0 deletions views/contact.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<%- include('partials/_header'); %>

<%- include('partials/_navigation'); %>

<div class="all-title-box">
<div class="container text-center">
<h1>Contact<span class="m_1">Lorem Ipsum dolroin gravida nibh vel velit.</span></h1>
</div>
</div>

<div id="contact" class="section wb">
<div class="container">
<div class="section-title text-center">
<h3>Get In Touch With Us!</h3>
<p class="lead">Let us give you more details about the special offer website you want us. Please fill out the form below. <br>We have million of website owners who happy to work with us!</p>
</div><!-- end title -->

<div class="row">
<div class="offset-1 col-xl-10 col-md-10 col-sm-10">
<div class="contact_form">
<div id="message"></div>
<form id="contactform" class="" action="/contact" name="contactform" method="POST">
<div class="row row-fluid">
<div class="col-lg-6 col-md-6 col-sm-6">
<input type="text" name="name" id="first_name" class="form-control" placeholder="Your Name">
</div>

<div class="col-lg-6 col-md-6 col-sm-6">
<input type="email" name="email" id="email" class="form-control" placeholder="Your Email">
</div>

<div class="col-lg-12 col-md-12 col-sm-12">
<textarea class="form-control" name="message" id="comments" rows="6" placeholder="Give us more details.."></textarea>
</div>
<div class="text-center pd">
<button type="submit" value="SEND" id="submit" class="btn btn-light btn-radius btn-brd grd1 btn-block">SEND</button>
</div>
</div>
</form>
</div>
</div><!-- end col -->
</div><!-- end row -->
</div><!-- end container -->
</div><!-- end section -->


<%- include('partials/_footer'); %>
202 changes: 0 additions & 202 deletions views/contact.html

This file was deleted.

2 changes: 1 addition & 1 deletion views/partials/_navigation.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% if(userIN) { %>
<li class="nav-item <%= page_name ==='dashboard' && 'active' %>" ><a class="nav-link" href="/users/dashboard">Dashboard</a></li>
<% } %>
<li class="nav-item"><a class="nav-link" href="contact.html">Contact</a></li>
<li class="nav-item <%= page_name ==='contact' && 'active' %>"><a class="nav-link" href="/contact">Contact</a></li>
</ul>

<% if(!userIN) { %>
Expand Down

0 comments on commit 1a4efef

Please sign in to comment.