-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
175 lines (139 loc) · 5.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
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
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'mms');
?>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>MMS</title>
</head>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
font-size: 17px;
}
#myVideo {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
</style>
</head>
<body>
<video autoplay muted loop id="myVideo">
<source src="video.png" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<script type="text/javascript">
console.log("hello");
function jsFunction(error) {
alert(error);
}
</script>
<div style="height:100px;"></div>
<div class="card shadow p-5 mt-5 bg-white rounded" style="margin: auto;width: 30vw;opacity:100%;border-radius: 15px; ">
<h1 style="text-align: center;width: max-content;margin: auto; ">Welcome to MMS</h1>
<div class="row" >
<!-- Login Form -->
<div class="col">
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="form-group mt-4">
<input type="hidden" name="type" value="login">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="Email" name="Email" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="pass" id="exampleInputPassword1" placeholder="Password">
</div>
<div style="height:20px;"></div>
<button type="submit" class="btn btn-primary" style="margin-left: 75px;width:200px">Login</button>
</form>
</div>
<!-- Register Form -->
<!-- <div class="col">
<form method="POST" action="">
<div class="form-group mt-4">
<input type="hidden" name="type" value="register">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="Email" name="Email" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="pass" id="exampleInputPassword1" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div> -->
</div>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$type = $_POST['type'];
if ($type == 'register') {
if (empty($name)) {
echo '<br>Email is empty';
}
if (empty($pass)) {
echo '<br>Password is empty';
}
$name = $_POST['Email'];
$pass = $_POST['pass'];
$q = " select * from users where username = '$name'";
$res = mysqli_query($con, $q);
if (mysqli_num_rows($res) == 1) {
echo '<br>User already exists';
} else {
$i = " insert into users values('$name', '','admin', '$pass')";
mysqli_query($con, $i);
echo '<script>jsFunction(\'User registration successfull\');</script>';
}
} else if ($type == 'login') {
$name = $_POST['Email'];
$pass = $_POST['pass'];
$q = " select * from users where username = '$name' and password = '$pass'";
$res = mysqli_query($con, $q);
if (mysqli_num_rows($res) != 0) {
$store = mysqli_fetch_array($res)['user_type'];
}
if (mysqli_num_rows($res) == 0) {
echo '<br>User credentials incorrect';
} else {
$_SESSION['username'] = $name;
if($store=='admin'){
header('location:admin/admins.php');
}
else if($store=='shop_manager'){
header('location:dashboard.php');
}
else if($store=='owner'){
header('location:ownerDashboard.php');
}
else if($store=='floor_manager'){
header('location:floor.php');
}
}
}else if($_POST['type']=='logout'){
$_SESSION['username']=null;
}
}
?>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</html>