-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathotp.html
271 lines (257 loc) · 8 KB
/
otp.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html lang="en">
<head>
<title>Masuk - Lupa Kata Sandi</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<meta name="robots" content="noindex,nofollow" />
<link rel="icon" href="assets/images/favicon.ico" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="assets/css/bootstrap.css" />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/signin.css" />
<link rel="stylesheet" href="assets/css/typography.css" />
<link rel="stylesheet" href="assets/css/otp.css" />
<link rel="stylesheet" href="https://cdn-uicons.flaticon.com/uicons-regular-rounded/css/uicons-regular-rounded.css"/>
<link
rel="stylesheet"
href="https://cdn-uicons.flaticon.com/uicons-solid-rounded/css/uicons-solid-rounded.css"
/>
<link rel="stylesheet" href="https://cdn-uicons.flaticon.com/uicons-bold-rounded/css/uicons-bold-rounded.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600;700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet"/>
</head>
<body class="text-center">
<nav class="navbar navbar-expand-md fixed-top background-transparent">
<a class="navbar-brand" href="login" title="login">
<i class="fi fi-sr-angle-left color-black600 bodytext1"></i>
</a>
</nav>
<form class="form-otp" action="reset_password" method="get">
<input type="email" name="email" id="inputEmail" required hidden />
<!-- <input type="number" name="otp" id="inputOTP" required hidden> -->
<i
class="fi fi-sr-shield-interrogation color-green500 headline2"
></i>
<p class="mb-2 mt-2 headline6 color-black700 font-weight-bold">
Masukan Kode OTP
</p>
<p class="mb-2 bodytext2 color-black500">
Masukan Kode OTP yang dikirim melalui email ke
<b class="color-black500" id="dataEmail"></b>
</p>
<div
id="otp"
class="inputs d-flex flex-row justify-content-center mt-3 mb-4"
>
<input
class="m-2 text-center otp-form bodytext2"
type="password"
id="first"
maxlength="1"
/>
<input
class="m-2 text-center otp-form bodytext2"
type="password"
id="second"
maxlength="1"
/>
<input
class="m-2 text-center otp-form bodytext2"
type="password"
id="third"
maxlength="1"
/>
<input
class="m-2 text-center otp-form bodytext2"
type="password"
id="fourth"
maxlength="1"
/>
<input
class="m-2 text-center otp-form bodytext2"
type="password"
id="fifth"
maxlength="1"
/>
<input
class="m-2 text-center otp-form bodytext2"
type="password"
id="sixth"
maxlength="1"
/>
</div>
<button type="submit" id="buttonSubmit" hidden></button>
<a
href="#"
id="resend"
onclick="resend()"
class="color-green500 bodytext2"
>
Kirim Ulang Kode
</a>
<p
id="counter"
class="color-black500 bodytext2"
style="display: none"
>
Silahkan tunggu 59 detik untuk mengirim ulang kode
</p>
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"
></script>
<script src="pwabuilder-sw-register.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"
></script>
<script src="assets/js/session.js"></script>
<script src="assets/js/bootstrap.js"></script>
<script>
var otpCode = "";
var codeTime = new Date().getTime();
const params = new URLSearchParams(window.location.search);
const resend = () => {
// request otp to server
// if success, show form otp
// if failed, show error message
otpCode = `${Math.floor(Math.random() * 900000) + 99999}`;
codeTime = new Date().getTime();
console.log(`Kode OTP : ${otpCode}`);
document.getElementById("resend").style.display = "none";
document.getElementById("counter").style.display = "block";
var timeleft = 59;
var downloadTimer = setInterval(function () {
if (timeleft <= 0) {
clearInterval(downloadTimer);
document.getElementById("counter").style.display =
"none";
document.getElementById("resend").style.display =
"block";
}
timeleft -= 1;
document.getElementById("counter").innerHTML =
"Silahkan tunggu " +
timeleft +
" detik untuk mengirim ulang kode";
}, 1000);
};
const checkParams = () => {
if (params.has("email")) {
const email = params.get("email");
// check email is available in server
// if available, show form otp
// if not available, back to login page
$("#dataEmail").val(email);
$("#inputEmail").val(email);
resend();
} else {
window.location.href = "login";
}
};
checkParams();
document.addEventListener("DOMContentLoaded", function (event) {
var code = "";
const OTPInput = () => {
const inputs = document.querySelectorAll("#otp > *[id]");
for (let i = 0; i < inputs.length; i++) {
inputs[i].addEventListener("keydown", function (event) {
if (event.key === "Backspace") {
code = code.slice(0, -1);
// console.log("result backspace : "+code);
inputs[i].value = "";
if (i !== 0) inputs[i - 1].focus();
} else {
if (
i === inputs.length - 1 &&
inputs[i].value !== ""
) {
return true;
} else if (
event.keyCode > 47 &&
event.keyCode < 58
) {
inputs[i].value = event.key;
if (i !== inputs.length - 1) {
inputs[i + 1].focus();
}
code += inputs[i].value;
event.preventDefault();
} else if (
event.keyCode > 64 &&
event.keyCode < 91
) {
inputs[i].value = String.fromCharCode(
event.keyCode
);
if (i !== inputs.length - 1) {
inputs[i + 1].focus();
}
code += inputs[i].value;
event.preventDefault();
}
// console.log(code);
if (code.length == 6) {
if (otpCode == code) {
// window.location.href = "reset_password";
const now = new Date().getTime();
if (checkDeffTime(codeTime, now) <= 5) {
console.log(
"Kode OTP sudah kadaluarsa :" +
checkDeffTime(codeTime, now)
);
localStorage.setItem("otp", code);
localStorage.setItem(
"forgot_password",
$("#inputEmail").val()
);
$("#buttonSubmit").click();
} else {
console.log(
"Kode OTP sudah kadaluarsa :" +
checkDeffTime(codeTime, now)
);
Swal.fire({
title: "Perhatian",
text: "Kode OTP sudah tidak berlaku",
icon: "error",
confirmButtonText: "Mengerti",
});
}
} else {
code = "";
for (
let j = 0;
j < inputs.length;
j++
) {
inputs[j].value = "";
}
inputs[0].focus();
Swal.fire({
title: "Perhatian",
text: "Kode OTP yang anda masukkan salah",
icon: "error",
confirmButtonText: "Mengerti",
});
}
}
}
});
}
};
OTPInput();
});
</script>
</body>
</html>