-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivateDisableAccount.php
204 lines (145 loc) · 5.97 KB
/
activateDisableAccount.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
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
<?php
//------------------------------>> CENTRALIZED TECHFEST NAME WITH YEAR
require_once "config/techfestName.php";
//------------------------------>> DB CONFIG
require_once "config/configPDO.php";
//------------------------>> SECRETS
require_once "./config/Secret.php";
//------------------------>> STARTING SESSION
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $techfestName ?> | REACTIVATE USER ACCOUNT</title>
<!-- Include Header Scripts -->
<?php include_once "includes/headerScripts.php";?>
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
</head>
<body>
<?php
try {
if (isset($_POST['reactivate'])) {
if (isset($_POST['h-captcha-response'])) {
$secretKey = $hcaptchaSecretKey;
$verifyResponse = file_get_contents('https://hcaptcha.com/siteverify?secret=' . $secretKey . '&response=' . $_POST['h-captcha-response']);
$response = json_decode($verifyResponse);
if ($response->success) {
# Avoid XSS
$email = htmlspecialchars($_POST['email']);
# sql Query
$sql = "SELECT * FROM user_information WHERE email = :email";
# Preparing query
$result = $conn->prepare($sql);
# Binding Values
$result->bindValue(":email", $email);
# Executing Query
$result->execute();
if ($result->rowCount() === 0) {
echo "<script>Swal.fire({
icon: 'error',
title: 'error',
text: 'No Such email present in database to reactivate your account'
})</script>";
} else {
# Generate Token
$token = bin2hex(random_bytes(15));
# Sql Query
$sql = "UPDATE user_information SET token = :token WHERE email = :email";
# Preparing Query
$result = $conn->prepare($sql);
# Binding Values
$result->bindValue(":token", $token);
$result->bindValue(":email", $email);
# Executing Query
$result->execute();
if ($result) {
/* PHP MAILER CODE */
include_once "./emailCode/emailDisableAccount.php";
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo " <script>Swal.fire({
icon: 'success',
title: 'Success',
text: 'Email Sent'
})</script>";
}
}
}
}else{
echo "<script>Swal.fire({
icon: 'warning',
title: 'Captcha Error',
text: 'Please fill Captcha'
})</script>";
}
}else{
echo "<script>Swal.fire({
icon: 'warning',
title: 'Captcha Error',
text: 'Please fill Captcha'
})</script>";
}
}
// -------------------------------->> ACTIVATE USER ACCOUNT
if (isset($_GET['token'])) {
# Avoid XSS
$token = htmlspecialchars($_GET['token']);
# Sql Query
$sql = "UPDATE user_information SET status = :active WHERE token = :token";
# Preparing Query
$result = $conn->prepare($sql);
# Binding Values
$result->bindValue(":active", "active");
$result->bindValue(":token", $token);
# Executing Query
$result->execute();
if ($result) {
echo "<script>Swal.fire({
icon: 'success',
title: 'Success',
text: 'Your account is successfully reactivated, We are happy to see you again'
})</script>";
}
}
} catch (PDOException $e) {
echo "<script>alert('We are sorry, there seems to be a problem with our systems. Please try again.');</script>";
# Development Purpose Error Only
echo "Error " . $e->getMessage();
}
?>
<!-- Include User Navbar -->
<?php include_once "includes/navbar.php";?>
<main class="container">
<div class="row">
<div class="col-md-6 my-5 offset-md-3">
<h1 class="font-time text-center">Activate Your Disable Account</h1>
<h5 class="text-center my-3">To activate your disable account please enter your email address in below
input
and check your email inbox, then click on link which is sent on your email your account will be
Reactivate.</h5>
<form action="" method="post">
<div class="form-group mt-2">
<label>Enter Your Email Address</label>
<input type="email" name="email" class="form-control" />
</div>
<div class="text-center my-2">
<div class="h-captcha text-center" data-sitekey="<?php echo $hcaptchaSiteKey; ?>"></div>
</div>
<input type="submit" name="reactivate" value="Submit" class="btn btn-primary btn-block rounded-pill">
<h6 class="mt-3"><a href="login.php">Click Here for Login Page</a></h6>
</form>
</div>
</div>
</main>
<!-- Include Footer & Footer Scripts -->
<?php include_once "includes/footer.php";
include_once "includes/footerScripts.php";
?>
<!-- Close Database Connection -->
<?php $conn = null;?>
</body>
</html>