forked from aadarshsenapati/Cartify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_verify.php
More file actions
96 lines (89 loc) · 3.79 KB
/
user_verify.php
File metadata and controls
96 lines (89 loc) · 3.79 KB
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
<?php
include("includes/connection.php");
if (!isset($_SESSION['otp'], $_SESSION['name'], $_SESSION['email'], $_SESSION['password'], $_SESSION['shop_id'])) {
header("Location: user_signup.php");
exit();
}
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$entered_otp = trim($_POST['otp']);
if ($entered_otp == $_SESSION['otp']) {
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$password = $_SESSION['password'];
$shop_id = $_SESSION['shop_id'];
$stmt = mysqli_prepare($conn, "INSERT INTO users (name, email, password, shop_id) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "sssi", $name, $email, $password, $shop_id);
if (mysqli_stmt_execute($stmt)) {
session_unset();
session_destroy();
header("Location: user_login.php");
exit();
} else {
$message = "Registration failed. Try again.";
}
} else {
$message = "Invalid OTP. Try again.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Verify OTP</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/css/bootstrap.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@300..700&family=Dosis:wght@200..800&family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=Inspiration&family=Italiana&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Playwrite+IN:wght@100..400&family=Poiret+One&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
<style>
body{
background: rgba(202, 144, 134, 0.7);
min-height: 50vh;
font-family: Rubik;
}
</style>
</head>
<?php
include("includes/header.php");
?>
<body>
<div class="container d-flex justify-content-center align-items-center" style="min-height: 100vh;">
<div class="card shadow p-4" style="max-width: 400px; width: 100%; background-color:rgba(202, 93, 74, 0.5);">
<h2 class="mb-4 text-center">Email Verification</h2>
<?php if ($message): ?>
<div class="alert alert-danger text-center" style="color: #111; background-color: #e9ecef; border-color: #bfc1c2;">
<?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
<form method="post" onsubmit="return validateOtpForm();">
<div class="mb-3 text-center">
<label class="form-label">Enter OTP sent to your email</label>
<input type="text" name="otp" id="otp" class="form-control form-control-sm mx-auto" style="max-width: 120px; text-align:center;" required>
</div>
<div id="formError" class="alert alert-danger text-center" style="color: #111; background-color: #e9ecef; border-color: #bfc1c2; display: none;"></div>
<div class="text-center">
<button type="submit" class="btn" style="background-color:rgba(202, 93, 74); width:120px;">Verify</button>
</div>
</form>
</div>
</div>
<script>
function validateOtpForm() {
var otp = document.getElementById('otp').value.trim();
var formError = document.getElementById('formError');
formError.style.display = 'none';
formError.textContent = '';
if (!otp) {
formError.textContent = "Please enter the OTP.";
formError.style.display = 'block';
return false;
}
if (!/^\d{6}$/.test(otp)) {
formError.textContent = "OTP must be a 6-digit number.";
formError.style.display = 'block';
return false;
}
return true;
}
</script>
</body>
</html>