-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
123 lines (109 loc) · 4.18 KB
/
index.php
File metadata and controls
123 lines (109 loc) · 4.18 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
<?php
session_start();
require 'connection.php';
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userType = $_POST['userType'];
$password = $_POST['password'];
$password = $conn->real_escape_string($password);
if ($userType == "admin") {
$email = $_POST['email'];
$email = $conn->real_escape_string($email);
$sql = "SELECT * FROM admin WHERE email = '$email' AND password = '$password'";
} elseif ($userType == "mechanic") {
$email = $_POST['email'];
$email = $conn->real_escape_string($email);
$sql = "SELECT * FROM mechanic WHERE email = '$email'";
} elseif ($userType == "shop_owner") {
$email = $_POST['email'];
$email = $conn->real_escape_string($email);
$sql = "SELECT * FROM shop_owner WHERE email = '$email'";
} elseif ($userType == "vehicle_owner"){
$email = $_POST['email'];
$email = $conn->real_escape_string($email);
$sql = "SELECT * FROM vehicle_owner WHERE email = '$email'";
} else {
echo "Invalid user type selected.";
exit();
}
$result = $conn->query($sql);
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
// Password verification
if ($userType == "mechanic" || $userType == "shop_owner" || $userType == "vehicle_owner") {
if (password_verify($password, $row['password'])) {
$_SESSION['userID'] = $row['userID'] ?? $row['ownerID'];
$_SESSION['name'] = $row['name'];
$_SESSION['email'] = $row['email'];
$_SESSION['userType'] = $userType;
header("Location: {$userType}/Login/login.php");
exit();
} else {
echo "Invalid password.";
}
} elseif ($userType == "admin" && $row['password'] == $password) {
$_SESSION['email'] = $row['email'];
$_SESSION['name'] = $row['name'];
$_SESSION['userType'] = $userType;
header("Location: admin/Login/login.php");
exit();
} else {
echo "Invalid password.";
}
} else {
echo "No user found with the provided credentials.";
}
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="left-panel">
<h2>Welcome Back!</h2>
<p>Login to continue to your dashboard</p>
</div>
<div class="form-box">
<form action="index.php" method="post">
<h1>Login</h1>
<div class="input-box">
<label for="userType">Login as:</label>
<select id="userType" name="userType" onchange="toggleInput()">
<option value="admin">Admin</option>
<option value="mechanic">Mechanic</option>
<option value="shop_owner">Shop Owner</option>
<option value="vehicle_owner">Vehicle Owner</option>
</select>
</div>
<div class="input-box" id="emailInput">
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" required>
</div>
<div class="input-box">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password" required>
</div>
<input type="submit" value="Login" class="btn">
</form>
</div>
</div>
<script>
function toggleInput() {
var userType = document.getElementById("userType").value;
var emailInput = document.getElementById("emailInput");
emailInput.style.display = "block";
}
// Initialize form
toggleInput();
</script>
</body>
</html>