-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
169 lines (145 loc) · 5.78 KB
/
index.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
include_once('./config/connectdb.php');
session_start();
$login_err = 'Sign in to start your session';
if (isset($_SESSION['user_role'])) {
if ($_SESSION['user_role'] === 'Admin') {
header("Location:./admin/dashboard.php");
} else if ($_SESSION['user_role'] === 'User') {
header("Location:./user/index.php");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>POS Management | Log in</title>
<!-- Google Font: Source Sans Pro -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
<!-- Font Awesome -->
<link rel="stylesheet" href="./plugins/fontawesome-free/css/all.min.css">
<!-- icheck bootstrap -->
<link rel="stylesheet" href="./plugins/icheck-bootstrap/icheck-bootstrap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="./dist/css/adminlte.min.css">
</head>
<body class="hold-transition bg-warning login-page">
<div class="login-box">
<div class="login-logo">
<a href="./index.php"><b>POS</b>Management</a>
</div>
<!-- /.login-logo -->
<div class="card shadow rounded">
<div class="card-body login-card-body my-2">
<?php echo '<p class="login-box-msg mb-2">' . $login_err . '</p>'; ?>
<form action="" method="post">
<div class="input-group mb-3">
<input type="email" name="email" class="form-control" placeholder="Email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" name="password" class="form-control" placeholder="Password" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<!-- /.col -->
<div class="col-12">
<button type="submit" name="submit" class="btn btn-primary btn-block">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>
<p class="text-center mb-1 mt-3">
<a href="#" onclick="swal('Attention','Please contact System Admin to recover your credentials.','warning');">I forgot my password</a>
</p>
</div>
<!-- /.login-card-body -->
</div>
</div>
<!-- /.login-box -->
<!-- Javascript -->
<!-- jQuery -->
<script src="/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/adminlte.min.js"></script>
<!-- Sweetalert JS v1.0.1 -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js'></script>
<!-- Custom Script -->
<script type="text/javascript">
// Sweet alert script function
function loginSuccess() {
swal({
title: "Login Success",
text: "Welcome back!",
type: "success",
buttons: false,
icon: "success",
timer: 2000,
});
}
function loginFail() {
swal({
title: "Login Failed!",
text: "Please enter correct details",
type: "error",
icon: "error",
buttons: false,
timer: 2000,
});
}
</script>
</body>
</html>
<?php
if (isset($_POST['submit'])) {
$useremail = htmlspecialchars($_POST['email']);
$userpassword = htmlspecialchars($_POST['password']);
// Check User Validation
$query = $con->prepare("SELECT * FROM table_users WHERE user_email=:email AND user_password=:password");
$query->bindValue(":email", $useremail);
$query->bindValue(":password", $userpassword);
$query->execute();
if ($query->rowCount() == 1) {
$row = $query->fetch(PDO::FETCH_ASSOC);
// var_dump($row);
if ($row['user_role'] === "Admin") {
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_name'] = $row['user_name'];
$_SESSION['user_email'] = $row['user_email'];
$_SESSION['user_role'] = $row['user_role'];
echo '
<script type="text/javascript">
loginSuccess();
</script>';
header("Refresh:2; ./admin/dashboard.php");
} elseif ($row['user_role'] === "User") {
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_name'] = $row['user_name'];
$_SESSION['user_email'] = $row['user_email'];
$_SESSION['user_role'] = $row['user_role'];
echo '
<script type="text/javascript">
loginSuccess();
</script>';
header("Refresh:2; ./user/index.php");
}
} else {
echo '
<script type="text/javascript">
loginFail();
</script>';
$login_err = "<span class='bg-maroon rounded shadow p-1'>Please enter correct login details</span>";
}
}