-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadduser.php
99 lines (88 loc) · 4.09 KB
/
adduser.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
<?php
$title = 'Add Admin | Safo Hall Pentvars';
require_once 'includes/session.php';
require_once 'includes/auth_check.php';
require_once 'includes/header.php';
require_once 'includes/db_conn.php';
require_once 'includes/errorToast.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = strtolower(trim($_POST['username']));
$password = $_POST['password'];
$system_password = $_POST['system_password'];
$result = $user->insertUserWithSystemPassword($username, $password, $system_password);
if (!$result['success']) {
displayErrorToast($result['error']);
} else {
$_SESSION['username'] = $username;
echo "<script>window.location.href='viewRegisteredStudents'</script>";
}
}
?>
<div class="d-flex justify-content-center">
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>"
class="form needs-validation p-3 mt-4 mb-4 bg-white rounded-2"
id="login_form"
novalidate method="POST">
<h1 class="text-center">Add Admin</h1>
<p class="text-center text-danger">For Administrators Only!</p>
<div>
<div>
<label for="username" class="form-label">New Username</label>
<input type="text" name="username" id="username"
class="form-control" required
value="<?php echo ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST['username'] : ''; ?>">
<div class="invalid-feedback">Username cannot be empty</div>
</div>
<div class="mt-3">
<label for="password" class="form-label">New Password</label>
<div class="input-group">
<input type="password" name="password" id="password"
class="form-control" required>
<button type="button" class="btn btn-outline-secondary toggle-password">
<i class="bi bi-eye"></i>
</button>
<div class="invalid-feedback">Password cannot be empty</div>
</div>
</div>
<div class="mt-3">
<label for="system_password" class="form-label">Enter System's Password</label>
<div class="input-group">
<input type="password" name="system_password" id="system_password"
class="form-control" required>
<button type="button" class="btn btn-outline-secondary toggle-password">
<i class="bi bi-eye"></i>
</button>
<div class="invalid-feedback">Password cannot be empty</div>
</div>
</div>
<input class="btn btn-primary w-100 border-0 mt-4" type="submit" name="submit">
</div>
</form>
</div>
<script defer>
document.addEventListener('DOMContentLoaded', () => {
// Select all toggle-password buttons and corresponding password fields
const toggleButtons = document.querySelectorAll('.toggle-password');
toggleButtons.forEach((button) => {
button.addEventListener('click', () => {
const passwordInput = button.previousElementSibling; // Select the related input
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
passwordInput.setAttribute('type', type);
// Toggle icon
button.innerHTML = type === 'password'
? '<i class="bi bi-eye"></i>'
: '<i class="bi bi-eye-slash"></i>';
});
});
// Bootstrap validation
const form = document.querySelector('#login_form');
form.addEventListener('submit', (event) => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated'); // Add Bootstrap validation styles
});
});
</script>
<?php require_once 'includes/footer.php'; ?>