-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotppage.php
147 lines (126 loc) · 4.37 KB
/
otppage.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
nav {
background-color: #333;
padding: 10px 0;
text-align: center;
}
nav a {
color: #fff;
margin: 0 10px;
text-decoration: none;
}
nav a:hover {
text-decoration: underline;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.signup-form {
width: 300px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
}
input[type="number"],
input[type="submit"] {
width: 100%;
padding: 12px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.login-link {
text-align: center;
}
</style>
</head>
<body>
<nav>
<a href="index.php">Home</a>
<a href="notices.php">Notices</a>
<a href="about.php">About</a>
<a href="contact.php">Contact</a>
<?php
if (isset($_SESSION['login']) && $_SESSION['login'] === true) {
echo '<a href="logout.php">Logout</a>';
} else {
echo '<a href="login.php">Login</a>';
}
?>
<a href="signup.php">Sign up</a>
</nav>
<div class="container">
<div class="signup-form">
<h2>Recover Your Account</h2>
<!-- PHP error/success messages -->
<form id="otpForm">
<label for="otp">Enter OTP</label>
<input type="number" id="otp" name="otp" placeholder="Enter OTP.." required>
<input type="submit" value="Submit">
</form>
<div class="login-link">
<p>Already have an account? <a href="login.php">Login here</a></p>
</div>
<div style="color: red; text-align: center;" id="responseMessage" class="response-message"></div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var otpForm = document.getElementById('otpForm');
var responseMessage = document.getElementById('responseMessage');
otpForm.addEventListener('submit', function(event) {
event.preventDefault();
var otp = document.getElementById('otp').value;
// AJAX request to send OTP for verification
var xhr = new XMLHttpRequest();
xhr.open('POST', 'otpphp.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200) {
var response = xhr.responseText;
responseMessage.innerHTML = response;
if(response.trim() === 'OTP verified successfully'){
setTimeout(function() {
responseMessage.innerHTML = '';
window.location.href="newpassword.php";
}, 3000);}
else{
setTimeout(function(){
responseMessage.innerHTML='';
},5000);}
} else {
responseMessage.innerHTML = 'Error: Request failed. Please try again later.';
}
};
var formData = 'otp=' + encodeURIComponent(otp);
xhr.send(formData);
});
});
</script>
</body>
</html>