From f9fad6aab5e9b13dfe609b1d7f8d1fbdfc04a6cb Mon Sep 17 00:00:00 2001 From: Juthatip McDevitt Date: Thu, 13 Jun 2024 10:56:05 -0500 Subject: [PATCH] setup admin authentication and created admin dashbord page --- docker-compose.yml | 22 ++++++++++++- hotel_booking/.gitignore | 3 +- hotel_booking/admin/components/utils.php | 29 ++++++++++++++++ hotel_booking/admin/dashboard.php | 42 ++++++++++++++++++++++++ hotel_booking/admin/index.php | 39 ++++++++++++++++++---- hotel_booking/admin/logout.php | 6 ++++ hotel_booking/style.css | 1 - 7 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 hotel_booking/admin/components/utils.php create mode 100644 hotel_booking/admin/dashboard.php create mode 100644 hotel_booking/admin/logout.php diff --git a/docker-compose.yml b/docker-compose.yml index c82db33..264598f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: \ No newline at end of file diff --git a/hotel_booking/.gitignore b/hotel_booking/.gitignore index 2c31100..8c75199 100644 --- a/hotel_booking/.gitignore +++ b/hotel_booking/.gitignore @@ -1 +1,2 @@ -images/* \ No newline at end of file +images/* +admin/components/db_config.php \ No newline at end of file diff --git a/hotel_booking/admin/components/utils.php b/hotel_booking/admin/components/utils.php new file mode 100644 index 0000000..3b13e61 --- /dev/null +++ b/hotel_booking/admin/components/utils.php @@ -0,0 +1,29 @@ + + window.location.href='index.php'; + "; + } + session_regenerate_id(true); + } + + function redirect($url){ + echo""; + } + + function alert($type, $msg){ + $bs_class = ($type == "success") ? "alert-success" : "alert-danger"; + echo << + $msg + + + alert; + } + +?> \ No newline at end of file diff --git a/hotel_booking/admin/dashboard.php b/hotel_booking/admin/dashboard.php new file mode 100644 index 0000000..46f1017 --- /dev/null +++ b/hotel_booking/admin/dashboard.php @@ -0,0 +1,42 @@ + + + + + + + Admin Dashboard | Midtown Hotel + + + + +
+

Admin Dashboard

+ Logout +
+ + + + + + \ No newline at end of file diff --git a/hotel_booking/admin/index.php b/hotel_booking/admin/index.php index 5c42cf8..d155457 100644 --- a/hotel_booking/admin/index.php +++ b/hotel_booking/admin/index.php @@ -1,7 +1,11 @@ @@ -9,7 +13,7 @@ Admin Login Panel | Midtown Hotel - + + num_rows==1){ + $row = mysqli_fetch_assoc($res); + $_SESSION['adminLogin'] = true; + $_SESSION['adminId'] = $row['sr_no']; + redirect('dashboard.php'); + } else{ + alert('error', 'Invalid credentials!'); + } + } + ?> - + \ No newline at end of file diff --git a/hotel_booking/admin/logout.php b/hotel_booking/admin/logout.php new file mode 100644 index 0000000..bde87cb --- /dev/null +++ b/hotel_booking/admin/logout.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/hotel_booking/style.css b/hotel_booking/style.css index 9089483..bf90497 100644 --- a/hotel_booking/style.css +++ b/hotel_booking/style.css @@ -540,4 +540,3 @@ ul{ margin-bottom: 30px; } } -