-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.php
109 lines (97 loc) · 3.48 KB
/
login.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
<?php
class Database {
private $servername = "localhost";
private $username = "root";
private $password = "";
private $database = "project_database";
private $conn;
public function __construct() {
$this->conn = new mysqli($this->servername, $this->username, $this->password, $this->database);
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
}
public function verifyUser($email, $post, $pwd) {
$query = "SELECT * FROM employee WHERE email_id='$email' AND post='$post' AND password='$pwd'";
$result = $this->conn->query($query);
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
$_SESSION['emp_id'] = $row['emp_id'];
$_SESSION['emp_name'] = $row['emp_name'];
switch ($post) {
case 'HR':
header('Location: hr_dashboard.php');
break;
case 'Manager':
header('Location: manager_dashboard.php');
break;
case 'Employee':
header('Location: employee_dashboard.php');
break;
}
} else {
header('Location: error.html');
}
}
public function closeConnection() {
$this->conn->close();
}
}
class UserAuthentication {
public function loginUser() {
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$post = $_POST['post'];
$pwd = $_POST['password'];
$db = new Database();
$db->verifyUser($email, $post, $pwd);
$db->closeConnection();
}
}
}
$auth = new UserAuthentication();
$auth->loginUser();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="login.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
</head>
<body>
<div class="wrapper">
<form action="login.php" method="post">
<h1>Login</h1>
<div class="input-box">
<input type="email" name="email" placeholder="Email Id" required="">
</div>
<select name="post">
<option value="Employee">Employee</option>
<option value="HR">HR</option>
<option value="Manager">Project Manager</option>
</select>
<div class="input-box">
<input id="pass" type="password" name="password" placeholder="Password" required="" ><i class="far fa-eye" id="togglePassword"></i>
</div>
<div class="remember-forgot">
<label><input type="checkbox">Remember Me</label> <a href="home.html"> < Back To Home</a>
</div><button type="submit" class="btn">Log In</button>
</form>
</div>
<script>const togglePassword = document.querySelector('#togglePassword');
const password = document.querySelector('#pass');
togglePassword.addEventListener('click', function (e) {
// toggle the type attribute
const type = password.getAttribute('type') === 'password' ? 'text' : 'password';
password.setAttribute('type', type);
// toggle the eye slash icon
this.classList.toggle('fa-eye-slash');
});
</script>
</body>
</html>