forked from Henry33y/Safo-hall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adduser.php
70 lines (60 loc) · 2.57 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
<?php
$title = 'Add User';
require_once 'includes/session.php';
require_once 'includes/auth_check.php';
require_once 'includes/header.php';
require_once 'includes/db_conn.php';
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$username = strtolower(trim($_POST['username']));
$password = $_POST['password'];
$result = $user->insertUser($username,$password);
if(!$result){
echo '<div class="alert alert-danger">Username or password is incorrect! Please try again</div>';
}else{
$_SESSION['username'] = $username;
// $_SESSION['id'] = $result['id'];
echo "<script>window.location.href='viewRegisteredStudents.php'</script>";
}
}
?>
<div class="d-flex justify-content-center">
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>" class="form needs-validation p-3 mt-4 bg-white rounded-2" id="login_form" novalidate method="POST">
<h1 class="text-center"><?php echo $title ?></h1>
<p class="text-center text-danger">For Administrators Only!</p>
<div>
<div>
<label for="" class="form-label">Username</label>
<input type="text" name="username" class="form-control" required value="<?php if($_SERVER['REQUEST_METHOD'] == 'POST') echo $_POST['username'];?>">
<div class="invalid-feedback">Username cannot be empty</div>
</div>
<div>
<label for="" class="form-label">Password</label>
<input type="password" name="password" id="password" class="form-control" required>
<div class="invalid-feedback">Password cannot be empty</div>
<input type="checkbox" class="me-2" id="showPassword"><span class="text-muted">Show Password</span>
</div>
<input class="btn btn-primary w-100" type="submit" name="submit">
</div>
</form>
</div>
<script defer>
const form = document.getElementById('login_form');
const showPasswordRadio = document.getElementById('showPassword');
const passwordInput = document.getElementById('password');
form.addEventListener('submit', (e) => {
if (!form.checkValidity()) {
e.preventDefault()
e.stopPropagation()
}
form.classList.add('was-validated')
}, false)
showPasswordRadio.addEventListener('change',()=>{
if(showPasswordRadio.checked){
passwordInput.type = "text"
}
else{
passwordInput.type = "password"
}
})
</script>
<?php require_once 'includes/footer.php' ?>