Skip to content

Commit ff78f69

Browse files
authored
Add the pop up show in the login page and validation on the image (#2)
1 parent 4bc2890 commit ff78f69

File tree

2 files changed

+106
-67
lines changed

2 files changed

+106
-67
lines changed

create.php

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
$email = $_SESSION['email'];
1717
//get user name and email from register table
18-
$getAdminData = "SELECT * FROM register WHERE email = '$email'";
19-
$resultData = mysqli_query($conn, $getAdminData);
20-
if($resultData ->num_rows > 0){
21-
$row2= $resultData->fetch_assoc();
22-
$adminName= $row2['name'];
23-
$adminEmail=$row2['email'];
24-
}
18+
$getAdminData = "SELECT * FROM register WHERE email = '$email'";
19+
$resultData = mysqli_query($conn, $getAdminData);
20+
if ($resultData->num_rows > 0) {
21+
$row2 = $resultData->fetch_assoc();
22+
$adminName = $row2['name'];
23+
$adminEmail = $row2['email'];
24+
}
2525

2626

2727
if (isset($_POST['submit'])) {
@@ -497,6 +497,10 @@
497497
<div class="col-md-6">
498498
<label for="image" class="form-label" style="font-size: 0.8rem;">Image</label>
499499
<input type="file" class="form-control" id="image" name="image" required accept=".jpg,.jpeg,.png" title="Only JPG, JPEG, and PNG formats are allowed">
500+
<!-- Error messages -->
501+
<div id="image-error" style="color:red; display:none;">Invalid image format. Only JPG, JPEG, and PNG formats are allowed.</div>
502+
<div id="size-error" style="color:red; display:none;">File size exceeds 2 MB.</div>
503+
<div id="dimension-error" style="color:red; display:none;">Image dimensions exceed the allowed 1024x768 size.</div>
500504
</div>
501505

502506
<div class="col-md-6">
@@ -628,6 +632,71 @@
628632
});
629633
});
630634
</script>
635+
<script>
636+
document.getElementById('image').addEventListener('change', function() {
637+
const file = this.files[0];
638+
const imageError = document.getElementById('image-error');
639+
const sizeError = document.getElementById('size-error');
640+
const dimensionError = document.getElementById('dimension-error');
641+
642+
// Reset error messages
643+
imageError.style.display = 'none';
644+
sizeError.style.display = 'none';
645+
dimensionError.style.display = 'none';
646+
647+
if (file) {
648+
const reader = new FileReader();
649+
650+
// Validate file size (2 MB limit)
651+
const maxSize = 2 * 1024 * 1024; // 2MB
652+
if (file.size > maxSize) {
653+
sizeError.style.display = 'block';
654+
this.value = ''; // Clear the file input
655+
return;
656+
}
657+
658+
// Validate file header (magic number)
659+
reader.onload = function(e) {
660+
const header = new Uint8Array(e.target.result).subarray(0, 4);
661+
let valid = false;
662+
663+
const jpg = header[0] === 0xFF && header[1] === 0xD8 && header[2] === 0xFF;
664+
const png = header[0] === 0x89 && header[1] === 0x50 && header[2] === 0x4E && header[3] === 0x47;
665+
666+
if (jpg || png) {
667+
valid = true;
668+
}
669+
670+
if (!valid) {
671+
imageError.style.display = 'block';
672+
document.getElementById('image').value = ''; // Clear the file input
673+
return;
674+
} else {
675+
imageError.style.display = 'none';
676+
677+
// Validate image dimensions
678+
const img = new Image();
679+
img.src = URL.createObjectURL(file);
680+
681+
img.onload = function() {
682+
const maxWidth = 1024; // Example standard width
683+
const maxHeight = 768; // Example standard height
684+
685+
if (img.width > maxWidth || img.height > maxHeight) {
686+
dimensionError.style.display = 'block';
687+
document.getElementById('image').value = ''; // Clear the file input
688+
} else {
689+
dimensionError.style.display = 'none';
690+
}
691+
};
692+
}
693+
};
694+
695+
reader.readAsArrayBuffer(file);
696+
}
697+
});
698+
</script>
699+
<!-- Validation Script of the header and the size of the image -->
631700
<script>
632701
const dataTable = new simpleDatatables.DataTable("#myTable2", {
633702
searchable: false,

pages-login.php

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
session_start();
33
include "db.php";
44

5-
6-
75
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
86

9-
// Get the user input
10-
$email = $_POST['email'];
11-
$password = $_POST['password'];
7+
// Get the user input and escape it for security
8+
$email = $conn->real_escape_string($_POST['email']);
9+
$password = $conn->real_escape_string($_POST['password']);
1210

13-
// Query to check if the username and password are correct
11+
// Query to check if the email and password are correct
1412
$result = $conn->query("SELECT * FROM register WHERE email='$email' AND password='$password'");
1513

1614
// If a match is found, set the session
1715
if ($result->num_rows > 0) {
1816
$_SESSION['email'] = $email; // Set session variable
19-
2017
header("Location: index.php"); // Redirect to the dashboard or home page
21-
18+
exit();
2219
} else {
23-
die("Error: The email '$email' doesn'nt exist");
20+
// Store the error message in a variable to use in the HTML
21+
$error_message = "Invalid email or password!";
2422
}
2523
}
26-
2724
?>
2825

2926

27+
28+
29+
3030
<!DOCTYPE html>
3131
<html lang="en">
3232

@@ -35,31 +35,16 @@
3535
<meta content="width=device-width, initial-scale=1.0" name="viewport">
3636

3737
<title>Login</title>
38-
<meta content="" name="description">
39-
<meta content="" name="keywords">
40-
41-
<!-- Favicons -->
42-
<link href="assets/img/favicon.png" rel="icon">
43-
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
4438

4539
<!-- Google Fonts -->
46-
<link href="https://fonts.gstatic.com" rel="preconnect">
47-
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
40+
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Nunito|Poppins" rel="stylesheet">
4841

4942
<!-- Vendor CSS Files -->
5043
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
51-
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
52-
<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
53-
<link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
54-
<link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
55-
<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
56-
<link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">
5744

58-
59-
<!--ALERTIFY CSS-->
60-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.14.0/build/css/alertify.min.css" />
61-
<!-- Bootstrap theme -->
62-
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.14.0/build/css/themes/bootstrap.rtl.min.css" />
45+
<!-- ALERTIFY CSS -->
46+
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.14.0/build/css/alertify.min.css"/>
47+
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.14.0/build/css/themes/bootstrap.rtl.min.css"/>
6348

6449
<style>
6550
.w-100 {
@@ -70,19 +55,12 @@
7055

7156
<!-- Template Main CSS File -->
7257
<link href="assets/css/style.css" rel="stylesheet">
73-
<style>
74-
.logo img {
75-
max-height: 50px;
76-
margin-right: 11px;
77-
}
78-
</style>
7958
</head>
8059

8160
<body>
8261

8362
<main>
8463
<div class="container">
85-
8664
<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
8765
<div class="container">
8866
<div class="row justify-content-center">
@@ -93,65 +71,57 @@
9371
<img src="assets/img/logo3.png" alt="">
9472
<span class="d-none d-lg-block">FingerLog</span>
9573
</a>
96-
</div><!-- End Logo -->
74+
</div>
9775

9876
<div class="card mb-3">
99-
10077
<div class="card-body">
101-
10278
<div class="pt-4 pb-2">
10379
<h5 class="card-title text-center pb-0 fs-4">Login to Your Account</h5>
10480
<p class="text-center small">Enter your email & password</p>
10581
</div>
10682

10783
<form class="row g-3 needs-validation" method="POST" action="">
108-
10984
<div class="col-12">
11085
<label for="yourEmail" class="form-label">Your Email</label>
11186
<input type="email" name="email" class="form-control" id="yourEmail" required>
112-
<div class="invalid-feedback">Please enter a valid Email adddress!</div>
87+
<div class="invalid-feedback">Please enter a valid Email address!</div>
11388
</div>
11489

11590
<div class="col-12">
11691
<label for="yourPassword" class="form-label">Password</label>
11792
<input type="password" name="password" class="form-control" id="yourPassword" required>
11893
<div class="invalid-feedback">Please enter your password!</div>
11994
</div>
95+
12096
<div class="col-6 d-flex">
12197
<button class="btn btn-outline-primary w-100" type="submit" name="submit" value="submit">Login</button>
122-
</div>
98+
</div>
12399
</form>
124100
</div>
125-
126-
127101
</div>
102+
128103
</div>
129104
</div>
130105
</div>
131106
</div>
132-
133107
</section>
134-
135-
</div>
136-
</main><!-- End #main -->
137-
138-
<a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
108+
</main>
139109

140110
<!-- Vendor JS Files -->
141-
<script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
142111
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
143-
<script src="assets/vendor/chart.js/chart.umd.js"></script>
144-
<script src="assets/vendor/echarts/echarts.min.js"></script>
145-
<script src="assets/vendor/quill/quill.js"></script>
146-
<script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
147-
<script src="assets/vendor/tinymce/tinymce.min.js"></script>
148-
<script src="assets/vendor/php-email-form/validate.js"></script>
149-
<!-- Template Main JS File -->
150-
<script src="assets/js/main.js"></script>
151112

152113
<!-- ALERTIFY JavaScript -->
153114
<script src="//cdn.jsdelivr.net/npm/alertifyjs@1.14.0/build/alertify.min.js"></script>
154115

116+
<!-- Display Alertify Pop-up at the Top of the Page -->
117+
<?php if (!empty($error_message)): ?>
118+
<script>
119+
// Set Alertify to display notifications at the top of the page
120+
alertify.set('notifier','position', 'top-center');
121+
alertify.error("<?= $error_message ?>");
122+
</script>
123+
<?php endif; ?>
124+
155125
</body>
156126

157-
</html>
127+
</html>

0 commit comments

Comments
 (0)