-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistration.php
executable file
·343 lines (306 loc) · 11.5 KB
/
Registration.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration</title>
<link rel="stylesheet" href="https://unpkg.com/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://unpkg.com/bs-brain@2.0.3/components/registrations/registration-3/assets/css/registration-3.css">
<!-- Jquery -->
<style>
.error{
color:red
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.3/dist/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.3/dist/additional-methods.min.js"></script>
<script>
$(document).ready(function() {
$('#registrationForm').validate({
rules: {
firstName: {
required: true,
regex: /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/
},
lastName: {
required: true,
regex: /^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$/
},
email: {
required: true,
email: true,
remote: {
url: 'check_email.php',
type: 'post',
data: {
email: function() {
return $('#email').val();
}
}
},
regex: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
},
password: {
required: true,
minlength: 8,
regex: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/
},
iAgree: {
required: true
}
},
messages: {
firstName: {
required: "Please enter your first name",
regex: "Please enter a valid first name"
},
lastName: {
required: "Please enter your last name",
regex: "Please enter a valid last name"
},
email: {
required: "Please enter your email address",
email: "Please enter a valid email address",
remote: "Email already exists",
regex: "Please enter a valid email address"
},
password: {
required: "Please enter a password",
minlength: "Your password must be at least 8 characters long",
regex: "Password must contain at least one uppercase letter, one lowercase letter, and one number"
},
iAgree: {
required: "You must agree to the terms and conditions"
}
},
errorPlacement: function(error, element) {
if (element.is(":checkbox")) {
error.appendTo(element.parents('.form-check'));
} else {
error.appendTo(element.parent());
}
},
submitHandler: function(form) {
form.submit(); // Submit the form if validation passes and email does not exist
}
});
});
</script>
<script>
$(document).ready(function() {
$('#email').blur(function() {
var email = $(this).val();
$.ajax({
url: 'check_mail.php',
type: 'POST',
data: { email: email },
success: function(response) {
if (response == 'exists') {
$('#email-error').text('Email already exists').show();
// Prevent form submission
$('#registrationForm').off('submit').submit(function(e) {
e.preventDefault();
});
} else {
$('#email-error').hide();
// Allow form submission
$('#registrationForm').off('submit').submit(function() {
return true;
});
}
}
});
});
});
</script>
</head>
<body>
<section class="p-3 p-md-4 p-xl-5">
<div class="container">
<div class="row">
<div class="col-12 col-md-6 bsb-tpl-bg-platinum">
<div class="d-flex flex-column justify-content-between h-100 p-3 p-md-4 p-xl-5">
<h3 class="m-0">Welcome!</h3>
<img class="img-fluid rounded mx-auto my-4" loading="lazy" src="img/FlightGO.jpeg" width="245" height="80" alt="BootstrapBrain Logo">
<p class="mb-0"></p>
</div>
</div>
<div class="col-12 col-md-6 bsb-tpl-bg-lotion">
<div class="p-3 p-md-4 p-xl-5">
<div class="row">
<div class="col-12">
<div class="mb-5">
<h2 class="h3">Registration</h2>
<h3 class="fs-6 fw-normal text-secondary m-0">Enter your details to register</h3>
</div>
</div>
</div>
<form action="Registration.php" method="post" enctype="multipart/form" id="registrationForm">
<div class="row gy-3 gy-md-4 overflow-hidden">
<div class="col-12">
<label for="firstName" class="form-label">First Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="firstName" id="firstName" placeholder="First Name">
</div>
<div class="col-12">
<label for="lastName" class="form-label">Last Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="lastName" id="lastName" placeholder="Last Name">
</div>
<div class="col-12">
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
<input type="email" class="form-control" name="email" id="email" placeholder="name@example.com">
<div id="email-error" class="error"></div>
</div>
<div class="col-12">
<label for="password" class="form-label">Password <span class="text-danger">*</span></label>
<input type="password" class="form-control" name="password" id="password" value="">
</div>
<div class="col-12">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" name="iAgree" id="iAgree">
<label class="form-check-label text-secondary" for="iAgree">
I agree to the <a href="#!" class="link-primary text-decoration-none">terms and conditions</a>
</label>
</div>
</div>
<div class="col-12">
<div class="d-grid">
<button class="btn bsb-btn-xl btn-primary" type="submit" name="submit" id="submit">Sign up</button>
</div>
</div>
</div>
</form>
<div class="row">
<div class="col-12">
<hr class="mt-5 mb-4 border-secondary-subtle">
<p class="m-0 text-secondary text-end">Already have an account? <a href="login.php" class="link-primary text-decoration-none">Sign in</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include_once ('connection.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
include_once('PHPMailer/Exception.php');
include_once('PHPMailer/PHPMailer.php');
include_once('PHPMailer/SMTP.php');
if (isset($_POST['submit'])) {
$fn = $_POST['firstName'];
$ln = $_POST["lastName"];
$em = $_POST['email'];
$pwd = $_POST['password'];
$token = uniqid() . uniqid();
$q = "INSERT INTO `User`(`Email`, `Password`,`Token`) VALUES ('$em','$pwd','$token')";
if (mysqli_query($conn, $q)) {
$mail = new PHPMailer(true);
try {
// Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->Username = 'Add your SMTP Username/Email'; // SMTP username
$mail->Password = 'Add SMTP password'; // SMTP password
$mail->SMTPSecure = "ssl";
$mail->Port = 465; // TCP port to connect to
$mail->SMTPDebug = 2;
// Recipients
$mail->setFrom('Sender Email', 'Sender Name'); // Sender's email address and name
$mail->addAddress($em, $fn); // Recipient's email address and name
// Attachments
//$mail->addAttachment('/path/to/attachment/file.pdf', 'Attachment.pdf'); // Path to the attachment and optional filename
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Account Verification';
$mail->Body = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Account Confirmation</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
text-align: center;
}
.container {
max-width: 600px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #007bff;
}
p {
margin-bottom: 20px;
}
.btn {
display: inline-block;
background-color: #007bff;
color: #fff;
text-decoration: none;
padding: 10px 20px;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h1>Account Confirmation</h1>
<p>Congratulations,' . $fn . '! Your account has been created successfully.</p>
<p>This email is for your account verification.</p>
<p>Kindly click on the link below to verify your account. You will be able to login into your account only after account verification.</p>
<a class="btn" href="http://localhost/FlightBooking/verify_account.php?em='.$em.'&token='.$token.'">Click here to verify your account</a>
</div>
</body>
</html>
';
// Send the email
if ($mail->send()) {
setcookie("success", "Registration Successfull. Activation mail is sent to your registered email account. Kindly activate your account to login.", time() + 2, "/");
?>
<script>
window.location.href = "login.php";
</script>
<?php
} else {
setcookie("error", "Error in sending mail. Please try again later.", time() + 2, "/");
?>
<script>
window.location.href = "Registration.php";
</script>
<?php
}
} catch (Exception $e) {
echo "Email sending failed. Error: {$mail->ErrorInfo}";
}
} else {
setcookie("error", "Error in registration. Please try again later.", time() + 2, "/");
?>
<script>
window.location.href = "Registration.php";
</script>
<?php
}
}
?>
</section>
</body>
</html>