-
Notifications
You must be signed in to change notification settings - Fork 1
/
specifyRange.php
190 lines (155 loc) · 7.99 KB
/
specifyRange.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
<?php
// Start the session
session_start();
// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
// Include the database connection
include 'config/db.php';
// Get session email
$email = $_SESSION['email'];
// Get user name, email, and role from the register table
$getAdminData = "SELECT * FROM register WHERE email = '$email'";
$resultData = mysqli_query($conn, $getAdminData);
if ($resultData->num_rows > 0) {
$row2 = $resultData->fetch_assoc();
$adminName = $row2['name'];
$adminEmail = $row2['email'];
$userRole = $row2['role']; // Assuming you have a 'role' column in the 'register' table
}
// Check if the user is an admin, otherwise redirect
if (isset($_SESSION['role']) &&$_SESSION['role'] != 'admin') {
// If the user is not an Admin, redirect to index page
header("Location: index.php");
exit();
}
if (isset($_POST['register'])) {
// Get form data and sanitize inputs
$name = mysqli_real_escape_string($conn, trim($_POST['name']));
$email = mysqli_real_escape_string($conn, trim($_POST['email']));
$password = mysqli_real_escape_string($conn, trim($_POST['password']));
$role = mysqli_real_escape_string($conn, trim($_POST['role']));
// Validate inputs
if (empty($name) || empty($email) || empty($password) || empty($role)) {
$error_message = "All fields are required!";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "Invalid email format!";
} else {
// Check if the email is already registered
$email_check_query = "SELECT * FROM register WHERE email='$email' LIMIT 1";
$result = mysqli_query($conn, $email_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if email exists
$error_message = "Email is already registered!";
} else {
// Store the plain password directly (not recommended for security reasons)
$sql = "INSERT INTO register (name, email, password, role) VALUES ('$name', '$email', '$password', '$role')";
if ($conn->query($sql) === TRUE) {
$_SESSION['message'] = "Registration successful!";
header('Location: pages-login.php'); // Redirect to login page after successful registration
exit();
} else {
$error_message = "Error: " . $conn->error;
}
}
}
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Register</title>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Nunito|Poppins" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- ALERTIFY CSS -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/alertify.min.css" />
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/build/css/themes/bootstrap.rtl.min.css" />
<style>
.w-100 {
margin-left: 122px;
width: 100% !important;
}
</style>
<!-- Template Main CSS File -->
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
<main>
<div class="container">
<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
<div class="d-flex justify-content-center py-4">
<a href="index.php" class="logo d-flex align-items-center w-auto">
<img src="assets/img/logo3.png" alt="">
<span class="d-none d-lg-block">FingerLog</span>
</a>
</div>
<div class="card mb-3">
<div class="card-body">
<div class="pt-4 pb-2">
<h5 class="card-title text-center pb-0 fs-4">Register a New Account</h5>
<p class="text-center small">Enter your name, email, password, and select your role</p>
</div>
<form class="row g-3 needs-validation" method="POST" action="" novalidate>
<div class="col-12">
<label for="yourName" class="form-label">Your Name</label>
<input type="text" name="name" class="form-control" id="yourName" required>
<div class="invalid-feedback">Please enter your name!</div>
</div>
<div class="col-12">
<label for="yourEmail" class="form-label">Your Email</label>
<input type="email" name="email" class="form-control" id="yourEmail" required>
<div class="invalid-feedback">Please enter a valid email address!</div>
</div>
<div class="col-12">
<label for="yourPassword" class="form-label">Password</label>
<input type="password" name="password" class="form-control" id="yourPassword" required minlength="8">
<div class="invalid-feedback">Please enter a password with at least 8 characters!</div>
</div>
<div class="col-12">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role" required>
<option value="">Select Role</option>
<option value="admin">Admin</option>
<option value="user">User</option>
</select>
<div class="invalid-feedback">Please select a role!</div>
</div>
<div class="col-12 d-flex justify-content-between">
<button class="btn btn-outline-primary" type="submit" name="register" value="register">Register</button>
<button class="btn btn-outline-secondary" type="reset">Reset</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</main>
<!-- Google reCAPTCHA -->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- Vendor JS Files -->
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ALERTIFY JavaScript -->
<script src="//cdn.jsdelivr.net/npm/[email protected]/build/alertify.min.js"></script>
<?php if (!empty($error_message)): ?>
<script>
// Set Alertify to display notifications at the top of the page
alertify.set('notifier', 'position', 'top-center');
alertify.error("<?= $error_message ?>");
</script>
<?php endif; ?>
</body>
</html>