forked from ABHRADEEP800/PHP-E_Commerce_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnf_acc.php
156 lines (134 loc) · 5.38 KB
/
cnf_acc.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
148
149
150
151
152
153
154
155
156
<?php
ob_start();
session_start();
require('env/database.php');
if (!isset($_SESSION['signup'])) {
header('location:signup.php');
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Signup</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel="icon" type="image/x-icon" href="assets/svg-logo/logo-bg.svg">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://kit.fontawesome.com/db79afedbd.js" crossorigin="anonymous"></script>
<script src="jquery.js"></script>
<link rel='stylesheet' type='text/css' media='screen' href='assets/css/main.css'>
</head>
<body>
<!-- ----------------------------------------------------Loading Screen-------------------------------------------------------- -->
<div id="loading">
<img src="assets/svg-logo/LOADER.svg" alt="Loading..." />
</div>
<script>
var loader = document.getElementById("loading");
window.addEventListener("load", function() {
loader.style.display = "none";
})
</script>
<!-------------------------------------------------body----------------------------------------------------------->
<div class="container mt-5">
<!-- otp card -->
<div class="col-lg-4 col-md-6 col-sm-10 mx-auto">
<div class="card ">
<div class="card-body">
<h5 class="card-title">Enter OTP</h5>
<p class="card-text">Enter the OTP sent to your email</p>
<form action="" method="POST">
<div class="mb-3">
<label for="otp" class="form-label">OTP</label>
<input type="number" class="form-control" id="otp" pattern="[0-9]{6}" maxlength="6" minlength="6" name="otp" placeholder="Enter OTP">
</div>
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
</div>
<div class="card-footer">
<div class="row">
<div class="col-6">
<a href="signup.php">Back</a>
</div>
<div class="col-6 text-end">
<form action="" method="POST">
<input type="hidden" name="email" value="email">
<button type="submit" name="resendOtp" class="btn btn-link" id="resend">Resend OTP</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<?php
if (isset($_POST['resendOtp'])) {
$data = $_SESSION['signup'];
$email = $data['user_email'];
$otp = rand(100000, 999999);
$_SESSION['otp'] = $otp;
require 'env/smtp.php';
$mail->addAddress($email); //Add a recipient
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'OTP for Signup';
$mail->Body = 'OTP for Signup is - ' . $otp;
if ($mail->send()) {
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['success']('OTP sent to your email');
</script>";
} else {
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['error']('Something Went Wrong!');
</script>";
}
}
if (isset($_POST['submit'])) {
if ($_SESSION['otp'] == $_POST['otp']) {
$data = $_SESSION['signup'];
$email = $data['user_email'];
$pass = $data['user_pass'];
$name = $data['user_name'];
$utype = $data['user_type'];
$query = "INSERT INTO `user`(`user_email`,`user_name`, `user_pass`, `user_type`) VALUES ('$email','$name','$pass','$utype')";
$result = mysqli_query($conn, $query);
if ($result) {
unset($_SESSION['captcha']);
unset($_SESSION['otp']);
unset($_SESSION['signup']);
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['success']('Registered Successfully');
setTimeout(function(){ window.location.href='login.php'; }, 5000);
</script>";
} else {
unset($_SESSION['captcha']);
unset($_SESSION['otp']);
unset($_SESSION['signup']);
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['error']('Something Went Wrong!');
setTimeout(function(){ window.location.href='signup.php'; }, 5000);
</script>";
}
} else {
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['error']('Wrong Otp!');
</script>";
}
}
ob_end_flush();
?>