Skip to content

Commit a205a2d

Browse files
committed
opt verification done
1 parent 67de630 commit a205a2d

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

using nodemailer for 2 way authentication/app.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ app.get('/',function(req,res){
2323
res.render('contact');
2424
});
2525

26+
var otp = Math.random();
27+
otp = otp * 1000000;
28+
otp = parseInt(otp);
29+
console.log(otp);
2630

2731
app.post('/send',function(req,res){
2832
const output= `
@@ -34,9 +38,50 @@ app.post('/send',function(req,res){
3438
<li> email: ${req.body.email}</li>
3539
<li> phone: ${req.body.phone}</li>
3640
</ul>
41+
<h3>Message</h3>
42+
<p>${req.body.message}</p>
3743
3844
`;
39-
});
45+
46+
let transporter = nodemailer.createTransport({
47+
host: "smtp.gmail.com",
48+
port: 465,
49+
secure: true,
50+
service : 'Gmail',
51+
52+
auth: {
53+
54+
pass: 'S@rth@k09',
55+
}
56+
57+
});
58+
59+
// send mail with defined transport object
60+
var mailOptions={
61+
to: req.body.email,
62+
subject: "Otp for registration is: ",
63+
html: "<h3>OTP for account verification is </h3>" + "<h1 style='font-weight:bold;'>" + otp +"</h1>" // html body
64+
};
65+
66+
transporter.sendMail(mailOptions, (error, info) => {
67+
if (error) {
68+
return console.log(error);
69+
}
70+
console.log('Message sent: %s', info.messageId);
71+
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
72+
73+
res.render('otp');
74+
});
75+
});
76+
77+
app.post('/sendotp',function(req,res){
78+
if(req.body.otp==otp){
79+
res.send("welcome");
80+
}
81+
else{
82+
res.render('otp',{msg : 'otp is incorrect'});
83+
}
84+
})
4085

4186
const PORT=process.env.PORT||3000;
4287
app.listen(PORT,()=>{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Sign-up form</title>
8+
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css" />
10+
<link rel="stylesheet" href="../public/css/style.css">
11+
</head>
12+
<body>
13+
<div class="container">
14+
<h1 class="brand"><span>Welcome User </span> Sign-up</h1>
15+
<div class="wrapper animated bounceInLeft">
16+
<div class="company-info">
17+
<h3>Panda Enterprises</h3>
18+
<ul>
19+
<li><i class="fa fa-road"></i> NIT KKR</li>
20+
<li><i class="fa fa-phone"></i> (+91) 9358668593</li>
21+
<li><i class="fa fa-envelope"></i> [email protected]</li>
22+
</ul>
23+
</div>
24+
<div class="contact">
25+
{{msg}}
26+
<form method="POST" action="sendotp">
27+
<p>
28+
<label>Enter otp</label>
29+
<input type="text" name="otp" required>
30+
</p>
31+
32+
33+
<p class="full">
34+
<button type="submit">Submit</button>
35+
</p>
36+
</form>
37+
</div>
38+
</div>
39+
</div>
40+
</body>
41+
</html>

0 commit comments

Comments
 (0)