-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
140 lines (122 loc) · 5.71 KB
/
index.php
File metadata and controls
140 lines (122 loc) · 5.71 KB
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
<html>
<head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title> Log In </title>
<link rel="stylesheet" href="Styles/mainStyleSheet.css">
<link rel="stylesheet" href="Styles/loginStyleSheet.css">
</head>
<body>
<?php
//function to verify POST data
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//session configurations
ini_set('session.cookie_secure', true);
//initializing vars
$usernameError=$passwordError=$loginError=$username=$password=$log="";
//checking for form submited with post method
if ($_SERVER["REQUEST_METHOD"] == "POST"){
include_once 'Configs/Conn.php';
session_start();
//include_once 'Configs/Config.php';
//checking for empty vars then putting the tested inputs in a variable
if(empty($_POST["username"])){
$usernameError="* Απαραίτητο Πεδίο";
echo "<script>document.getElementById('username').style.backgroundColor='#d95f57';</script>";
$log=$log." Empty username.";
} else {
$username = test_input($_POST["username"]);
}
if(empty($_POST["password"])){
$passwordError="* Απαραίτητο Πεδίο";
echo "<script>document.getElementById('password').style.borderColor='tomato';</script>";
$log=$log." Empty password.";
} else {
$password = test_input($_POST["password"]);
}
// Check user credentials in the database
// Querying the database for the username and fetching id and password
$sql = "SELECT id, username, password, isAdmin, isActive FROM user WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
// Close statement
$stmt->close();
if($user){ //user found
// Check if user is active and verify password
if ($user['isActive'] && password_verify($password, $user["password"])) {
// Set session variables
//static $SESSION;
$_SESSION['user_id'] = $user["id"];
$_SESSION['user'] = $user["username"];
$_SESSION['isAdmin']=$user["isAdmin"];
// Redirect to a secured page
if($user["isAdmin"]){
//close conn
$conn->close();
header("Location: admin/index.php");
exit();
} else if (!$user["isAdmin"]){
//close conn
$conn->close();
header("Location: user/index.php");
exit();
}
} else {
// Invalid credentials
$loginError = "Λάθος username ή κωδικός πρόσβασης!";
}
}
//close conn
$conn->close();
}
?>
<div class="flex-container">
<div id="appInfo">
<img src="SAEK_logo.png" alt="Θ.Σ.Α.Ε.Κ. Αιγάλεω" width="30%" id="logo">
<p id="infoParagraph">Η παρούσα εφαρμογή αναπτύχθηκε για τη Θ.Σ.Α.Ε.Κ. Αιγάλεω κατά το ακαδημαϊκό έτος 2023-2024.
Σκοπός είναι η αντικατάσταση του παραδοσιακού τρόπου συμπλήρωσης των βιβλίων ύλης με ένα σύγχρονο και εύχρηστο σύστημα που θα
επιτρέπει μεγαλύτερη ευελιξία και αμεσότητα. Πέρα από το περιβάλλον των διδασκόντων, περιλαμβάνεται και περιβάλλον για διαχειριστές
μέσα από το οποίο οι ίδιοι θα μπορούν να διαχειριστούν τα εξάμηνα της σχολής, τα μαθήματα, τους χρήστες αλλά και να λάβουν συγκεντρωτικά
τις εγγραφές από τα βιβλία ύλης με μερικά κλικ.<br><br>•••<br><br><!-- Η ανάπτυξη του συστήματος ανατέθηκε από τη διεύθυνση του Θ.Σ.Α.Ε.Κ. Αιγάλεω σε καταρτιζόμενους
της σχολής εθελοντικά με σκοπό την βελτίωση των ικανοτήτων τους μέσω της παραγωγής πρωτότυπου υλικού.<br><br> -->
Ανάπτυξη: Ιωάννης Μαμάης - Ηλίας Μοτσενίγος.
</p>
</div>
<div id="formBox">
<h1>Βιβλίο Ύλης</h1>
<form name="Login" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<label for="username"> • Username • </label>
<input type="text" name="username" size="20" maxlength="20" id="username"/> <?php if(isset($usernameError)){echo "$usernameError";} ?> <br>
<br>
<label for="password"> • Password • </label>
<input type="password" name="password" size="20" maxlength="20" id="password"/> <?php if(isset($passwordError)){echo "$passwordError";} ?> <br>
<br>
<br>
<button type="submit"> Είσοδος </button> <br> <?php if(isset($loginError)){echo "$loginError";} ?>
</form>
<div id="buttonBox">
<a href="common/newUser.php?p=6" class="btn">Εγγραφή Νέου Χρήστη</a>
<a href="passwordrecovery/index.php" class="btn">Επαναφορά Κωδικού</a>
</div>
</div>
</div>
<!-- script for adding red borders to empty input fields-->
<script>
document.addEventListener("DOMContentLoaded", function() {
if ("<?php echo !empty($usernameError); ?>") {
document.getElementById('username').style.borderColor = '#d95f57';
}
if ("<?php echo !empty($passwordError); ?>") {
document.getElementById('password').style.borderColor = '#d95f57';
}
});
</script>
</body>
</html>