-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (56 loc) · 1.44 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express=require("express")
const bodyparser=require("body-parser")
const app=express()
app.use(bodyparser.urlencoded({extended:true}))
app.use(express.static("public"))
const nodemailer=require("nodemailer")
let otp=""
const transporter=nodemailer.createTransport({
service:'gmail',
auth:{
user:"your email id",
pass:"your pass key "
}
})
function genotp() {
let a=Math.floor(Math.random()*9).toString()
a=a+Math.floor(Math.random()*9)
a=a+Math.floor(Math.random()*9)
a=a+Math.floor(Math.random()*9)
return a
}
app.listen(3000,()=>{
console.log("Listening at 3000");
})
app.get("/",(req,res)=>{
res.sendFile(__dirname+"/pages/index.html")
})
app.post("/send",(req,res)=>{
let mail_address=req.body.email
console.log(mail_address);
otp=genotp().toString()
console.log(otp);
let details={
from:"your email id",
to:mail_address,
subject:"OTP",
text:otp
}
transporter.sendMail(details,((err,info)=>{
if(err){
console.log(err);
}else{
console.log("sent"+info.response);
}
}))
res.sendFile(__dirname+"/pages/verify.html")
})
app.post("/verify",(req,res)=>{
let user_input_otp=req.body.otp.toString()
console.log(user_input_otp);
if(user_input_otp===otp){
res.sendFile(__dirname+"/pages/home.html")
}else{
res.sendFile(__dirname+"/pages/verify")
}
})