-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
85 lines (73 loc) · 2.12 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const config=require('./config');
const express = require("express");
const bodyParser = require("body-parser");
const fetch = require("node-fetch");
const app= express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
app.get("/",(req,res)=>{
res.sendFile(__dirname+"/index.html");
});
app.post("/",async (req,res)=>{
const number = req.body.number;
const url= `https://api.tiniyo.com/v1/Account/${config.AuthID}/Verifications`;
const options={
method:"POST",
headers:{
"Authorization": `Basic ${config.encodedAuth}`,
"content-type": "application/json"
},
body:JSON.stringify({
"dst":`91${number}`
})
};
const response= await fetch(url,options)
.then(res=> res.json())
.then(data=> {
console.log(data);
})
.catch(err=>{
console.log(err);
});
res.redirect("/otp");
});
app.get("/otp",(req,res)=>{
res.sendFile(__dirname+"/public/verification.html");
});
app.post("/otp",async (req,res)=>{
const number = req.body.number;
const otp= req.body.otp;
const url= `https://api.tiniyo.com/v1/Account/${config.AuthID}/VerificationsCheck`;
const options={
method:"POST",
headers:{
"Authorization": `Basic ${config.encodedAuth}`,
"content-type": "application/json"
},
body:JSON.stringify({
"dst":`91${number}`,
"code":`${otp}`
})
};
const response= await fetch(url,options)
.then(res=> res.json())
.then(data=> {
if(data.status==="success"){
res.redirect("/success");
}else{
res.redirect("/fail");
}
})
.catch(err=>{
console.log(err);
});
});
app.get("/success",(req,res)=>{
res.sendFile(__dirname+"/public/success.html");
});
app.get("/fail",(req,res)=>{
res.sendFile(__dirname+"/public/fail.html");
})
app.listen(process.env.PORT || 3001,()=>{
console.log("Server started on port 3001");
});