-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotp.html
70 lines (65 loc) · 3.04 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
<html>
<head>
<link rel='stylesheet' href='form-style.css' type='text/css' />
</head>
<body>
<h1 class="firstNameBox"></h1>
<div class="otp-form">
<input class="otpField" type="text" maxlength=4 />
<h6 class="invalid-otp"></h6>
<h3 class="randomNo"></h3>
<button class="otpSubmit">Submit OTP</button>
</div>
<div class="success-container">
<h3>Validation Successful. Please wait while we redirect you to Pixel6 home page</h3>
</div>
<script>
// Getting first name and mobile number from URL params.
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const firstNameUrlParam = urlParams.get('firstName');
const mobileNoUrlParam = urlParams.get('mobileNo');
// Displaying OTP message.
const firstnameBoxEl = document.querySelector('.firstNameBox');
firstnameBoxEl.innerHTML = `Dear ${firstNameUrlParam}, Thank you for inquiry. A 4 digit mobile no is sent to your mobile no:${mobileNoUrlParam}, please enter it in following box and submit for confirmation`;
const otpEl = document.querySelector('.otpField');
otpEl.addEventListener('input', () => {
otpEl.value = otpEl.value.replace(/\D/g, '');
});
// To generate 4 digit random number.
var randomNumber = Math.floor(1000 + Math.random() * 9000);
const randomNoEl = document.querySelector('.randomNo');
randomNoEl.innerHTML = `Please enter the given OTP number: ${randomNumber}`;
// To check whether entered OTP matches with the OTP generated.
const otpEnteredButton = document.querySelector('.otpSubmit');
let counter = 0;
const invalidOtpField = document.querySelector('.invalid-otp');
const successContainerEl = document.querySelector('.success-container');
const otpFormEl = document.querySelector('.otp-form');
otpEnteredButton.addEventListener('click', () => {
const otpEntered = otpEl.value;
// Entered OTP is correct so redirect to Pixel6 ome page.
if (otpEntered == randomNumber) {
otpFormEl.classList.add('hide');
successContainerEl.classList.add('show');
// Setting a time out of 3 secons before user is redirected to Pixel6 site.
setTimeout(function(){ window.location.href = 'http://pixel6.co/' }, 3000);
} else {
if (otpEntered === ''|| otpEntered === 'null') {
counter = counter;
} else {
// Counter to check whether user has entered wrong OTP more than 3 times.
counter = counter + 1;
invalidOtpField.innerHTML = `Invalid OTP. Please try again. Attempt: ${counter}`;
invalidOtpField.classList.add('active');
// Checks if wrong OTP is entered 3 times then redirect user to Pixel site 404 not found page.
if (counter > 2) {
otpEnteredButton.disabled = true;
window.location.href = 'http://pixel6.co/404/';
}
}
}
});
</script>
</body>
</html>