/
login.html
111 lines (110 loc) · 4.99 KB
/
login.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cowin Vaccine Tracker - Login</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.7/tailwind.min.css" integrity="sha512-y6ZMKFUQrn+UUEVoqYe8ApScqbjuhjqzTuwUMEGMDuhS2niI8KA3vhH2LenreqJXQS+iIXVTRL2iaNfJbDNA1Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.7/base.min.css" integrity="sha512-4VB9GCwtWOJxNtYsvJ7qUjRCTtlHpBYKQwr5ae/GgAd/ti9SFx0yh/CmAAO2H8ymeRJxg1F578l+7FAz1DuKgA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="w-full bg-gray-200 h-screen flex flex-col p-10 items-center justify-center">
<h1 id="loading">Loading...</h1>
<div id="sendOtp" style="display: none;" class="w-4/5 flex flex-col space-y-5 items-center shadow-lg bg-white p-12 rounded-lg">
<h1 class="text-lg text-center font-semibold">
Cowin Vaccine Tracker Login
</h1>
<span id="yourNumber" class="block text-center">Your Number:</span>
<button onclick="sendOtp()" class="p-3 text-center w-full text-white rounded-md bg-blue-600">
Send OTP
</button>
</div>
<div id="verifyOtp" style="display: none;" class="w-4/5 flex items-center space-y-5 flex-col shadow-lg bg-white p-12 rounded-lg">
<h1 class="text-lg text-center font-semibold">
Cowin Vaccine Tracker Login
</h1>
<span class="text-sm">Enter OTP:</span>
<input class="border w-full border-2 border-block p-2 rounded-md" type="text" id="otpBox" required>
<h5 id="wrongOtp" style="display: none;" class="text-sm text-red-600">Wrong OTP! Please try again!</h5>
<button onclick="verifyOtp()" class="text-center w-full p-3 text-white rounded-md bg-blue-600">
Verify OTP
</button>
</div>
<div id="success" style="display: none;" class="w-4/5 flex items-center space-y-5 flex-col shadow-lg bg-white p-12 rounded-lg">
<span>Successfully logged in! Close this window and check your status by sending /status to bot.</span>
</div>
</div>
</body>
<script src="/public/sha256.min.js"></script>
<script src="/axios/axios.min.js"></script>
<script>
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
document.getElementById('yourNumber').innerText += (' ' + params.mobile)
const chatId = params.chatId
const loader = document.getElementById('loading')
var txnId = null
var token = null
if (!chatId || !params.mobile) {
loader.innerText = "ERROR: No number/ChatId provided"
} else {
loader.style.display = 'none'
document.getElementById('sendOtp').style.display = 'block'
}
async function sendOtp () {
const postData = {
mobile: params.mobile,
secret: "U2FsdGVkX18BUM3xhsRAs3GJT2PpZV1UFSdrdLzmgEKxiTmyTvBCvRjEPJT6w+mL7Tu9EneKydezRLPWDXGFdw=="
}
const res = await axios({
method: 'POST',
url: 'https://cdn-api.co-vin.in/api/v2/auth/generateMobileOTP',
data: postData
})
console.log(res.data)
txnId = res.data.txnId
document.getElementById('sendOtp').style.display = 'none'
document.getElementById('verifyOtp').style.display = 'block'
}
async function verifyOtp() {
document.getElementById('wrongOtp').style.display = 'none'
const otp = document.getElementById('otpBox').value
const postData = {
txnId,
otp: await sha256(otp)
}
try {
const res = await axios({
url: 'https://cdn-api.co-vin.in/api/v2/auth/validateMobileOtp',
method: 'POST',
data: postData
})
token = res.data.token
} catch (err) {
document.getElementById('otpBox').value = ""
document.getElementById('wrongOtp').style.display = 'block'
return
}
try {
await axios({
url: '/api/bot/handshake',
method: 'POST',
data: {
chatId,
token
},
headers: {
'x-sauce': 'true'
}
})
document.getElementById('verifyOtp').style.display = 'none'
document.getElementById('success').style.display = 'block'
} catch (err) {
document.getElementById('verifyOtp').style.display = 'none'
loader.style.display = 'block'
loader.innerText = "Unable to handshake with Bot! Please try again by refreshing the page!"
}
}
</script>
</html>