setup admin authentication and created admin dashbord page
This commit is contained in:
parent
92cd23b3af
commit
f9fad6aab5
7 changed files with 133 additions and 9 deletions
|
@ -7,4 +7,24 @@ services:
|
|||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: example
|
||||
# (this is just an example, not intended to be a production configuration)
|
||||
MYSQL_DATABASE: hotel_booking
|
||||
MYSQL_USER: db_user
|
||||
MYSQL_PASSWORD: db_user_pass
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- ./dbdata:/var/lib/mysql
|
||||
phpmyadmin:
|
||||
image: phpmyadmin/phpmyadmin
|
||||
container_name: pma
|
||||
links:
|
||||
- db
|
||||
environment:
|
||||
PMA_HOST: db
|
||||
PMA_PORT: 3306
|
||||
PMA_ARBITRARY: 1
|
||||
restart: always
|
||||
ports:
|
||||
- 8081:80
|
||||
volumes:
|
||||
dbdata:
|
1
hotel_booking/.gitignore
vendored
1
hotel_booking/.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
images/*
|
||||
admin/components/db_config.php
|
29
hotel_booking/admin/components/utils.php
Normal file
29
hotel_booking/admin/components/utils.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
function adminLogin(){
|
||||
session_start();
|
||||
if(!(isset($_SESSION['adminLogin']) && $_SESSION['adminLogin'] == true)){
|
||||
echo"<script>
|
||||
window.location.href='index.php';
|
||||
</script>";
|
||||
}
|
||||
session_regenerate_id(true);
|
||||
}
|
||||
|
||||
function redirect($url){
|
||||
echo"<script>
|
||||
window.location.href='$url';
|
||||
</script>";
|
||||
}
|
||||
|
||||
function alert($type, $msg){
|
||||
$bs_class = ($type == "success") ? "alert-success" : "alert-danger";
|
||||
echo <<<alert
|
||||
<div class="alert $bs_class alert-dismissible fade show custom-alert" role="alert">
|
||||
<strong class="me-3">$msg</strong>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
alert;
|
||||
}
|
||||
|
||||
?>
|
42
hotel_booking/admin/dashboard.php
Normal file
42
hotel_booking/admin/dashboard.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
require('components/utils.php');
|
||||
adminLogin();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard | Midtown Hotel</title>
|
||||
<?php require('components/link.php') ?>
|
||||
<style>
|
||||
.btn-main{
|
||||
background-color: #B6C2C2;
|
||||
border: none;
|
||||
color: #112E2E;
|
||||
padding: 6px 12px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.btn-main:hover{
|
||||
background-color: lightgray;
|
||||
color: black;
|
||||
transition: all 0.5s ease;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<div class="container-fluid text-light p-3 d-flex align-items-center justify-content-between" style="background-color: #112E2E;">
|
||||
<h4>Admin Dashboard</h4>
|
||||
<a href="logout.php" class="btn btn-main">Logout</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<?php require('components/script.php') ?>
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +1,11 @@
|
|||
<?php
|
||||
|
||||
require('components/utils.php');
|
||||
require('components/db_config.php');
|
||||
|
||||
session_start();
|
||||
if((isset($_SESSION['adminLogin']) && $_SESSION['adminLogin'] == true)){
|
||||
redirect('dashboard.php');
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
@ -9,7 +13,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Login Panel | Midtown Hotel</title>
|
||||
<?php require('./components/link.php') ?>
|
||||
<?php require('components/link.php') ?>
|
||||
<style>
|
||||
.btn-main{
|
||||
background-color: #112E2E;
|
||||
|
@ -32,29 +36,52 @@
|
|||
transform: translate(-50%, -50%);
|
||||
width: 300px;
|
||||
}
|
||||
.custom-alert{
|
||||
position: fixed;
|
||||
top: 25px;
|
||||
right: 25px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-form text-center rounded shadow overflow-hidden" style="background-color: #B6C2C2;">
|
||||
<form>
|
||||
<form method="POST">
|
||||
<div class="py-2 d-flex justify-content-between align-items-center" style="background-color: #112E2E;">
|
||||
<img src="../images/logo-white.png" style="width: 100px;"/>
|
||||
<h5 class="text-white" style="font-weight: 600; text-transform: uppercase; margin-right: 20px;">Admin Login</h5>
|
||||
</div>
|
||||
<div class="m-4">
|
||||
<div class="mb-4">
|
||||
<input name="admin_name" type="text" class="form-control shadow-none" placeholder="Username"/>
|
||||
<input required name="admin_name" type="text" class="form-control shadow-none" placeholder="Username"/>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<input name="admin_pass" type="password" class="form-control shadow-none" placeholder="Password"/>
|
||||
<input required name="admin_pass" type="password" class="form-control shadow-none" placeholder="Password"/>
|
||||
</div>
|
||||
<button name="login" type="submit" class="btn btn-main">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if(isset($_POST['login'])){
|
||||
$frm_data = filteration($_POST);
|
||||
$query = "SELECT * FROM `admin_creds` WHERE `admin_name`=? AND `admin_pass`=?";
|
||||
$values = [$frm_data['admin_name'], $frm_data['admin_pass']];
|
||||
|
||||
$res = select($query, $values, "ss");
|
||||
if($res->num_rows==1){
|
||||
$row = mysqli_fetch_assoc($res);
|
||||
$_SESSION['adminLogin'] = true;
|
||||
$_SESSION['adminId'] = $row['sr_no'];
|
||||
redirect('dashboard.php');
|
||||
} else{
|
||||
alert('error', 'Invalid credentials!');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<?php require('./components/script.php') ?>
|
||||
<?php require('components/script.php') ?>
|
||||
</body>
|
||||
</html>
|
6
hotel_booking/admin/logout.php
Normal file
6
hotel_booking/admin/logout.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
require('components/utils.php');
|
||||
session_start();
|
||||
session_destroy();
|
||||
redirect('index.php');
|
||||
?>
|
|
@ -540,4 +540,3 @@ ul{
|
|||
margin-bottom: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue