diff --git a/app/controllers/Logout.php b/app/controllers/Logout.php index e7cd9930..46256ec6 100644 --- a/app/controllers/Logout.php +++ b/app/controllers/Logout.php @@ -6,6 +6,7 @@ class Logout { public function index(): void { $data['email'] = empty($_SESSION['USER']) ? '' : $_SESSION['USER']->email; + setcookie('jwt_auth_token', '', time() - 1, '/'); session_destroy(); redirect('home'); } diff --git a/app/core/App.php b/app/core/App.php index dca02778..cb012e73 100755 --- a/app/core/App.php +++ b/app/core/App.php @@ -116,9 +116,17 @@ public function loadController(): void { // } // } // $this->runMiddleware(); - $user = AuthMiddleware::run_middleware($this->controller, $this->method); + $user = UserMiddleware::user(AuthMiddleware::run_middleware($this->controller, $this->method)); + // make user global to all views + + $_SESSION['USER'] = $user; + // show($user); + // show($_SESSION['USER']); + + // show($user); call_user_func_array([$controller, $this->method], $URL); + } } diff --git a/app/core/init.php b/app/core/init.php index c07e7841..0c001cb4 100755 --- a/app/core/init.php +++ b/app/core/init.php @@ -22,3 +22,4 @@ require 'Controller.php'; require 'App.php'; require '../app/middlewares/AuthMiddleware.php'; +require '../app/middlewares/UserMiddleware.php'; diff --git a/app/middlewares/AuthMiddleware.php b/app/middlewares/AuthMiddleware.php index 795dfd85..fdc2ce64 100644 --- a/app/middlewares/AuthMiddleware.php +++ b/app/middlewares/AuthMiddleware.php @@ -25,6 +25,7 @@ public static function run_middleware(string $controller, string $method): mixed $authRequired = [ 'Home' => ['index', 'method2'], 'Controller2' => ['method3'], + // 'Profile' => ['index', 'edit', 'update'], ]; $unauthRequired = [ 'Login' => ['index'], @@ -40,6 +41,8 @@ public static function run_middleware(string $controller, string $method): mixed if (isset($unauthRequired[$currentController]) && in_array($method, $unauthRequired[$currentController])) { Self::not_authenticated(); + }else { + Self::check(); } // return Self::$user; diff --git a/app/middlewares/UserMiddleware.php b/app/middlewares/UserMiddleware.php index e69de29b..6940fd97 100644 --- a/app/middlewares/UserMiddleware.php +++ b/app/middlewares/UserMiddleware.php @@ -0,0 +1,47 @@ +first([ + 'user_id'=> $user['id'] + ]); + // echo $customer; + $user = (object) array_merge((array) $user, (array) $customer); + return $user; + } + if ($user['role'] == 'guide') { + $guide = new GuideModel; + $guide = $guide->first([ + 'user_id'=> $user['id'] + ]); + // show($d); + $user = (object) array_merge((array) $user, (array) $guide); + return $user; + } + if ($user['role'] == 'rental_service') { + $rental_service = new RentalServiceModel; + $rental_service = $rental_service->first([ + 'user_id'=> $user['id'] + ]); + $user = (object) array_merge((array) $user, (array) $rental_service); + return $user; + } + } + +} + + + + + + + +?> \ No newline at end of file diff --git a/app/models/Customer.php b/app/models/Customer.php index 978de850..753f360a 100644 --- a/app/models/Customer.php +++ b/app/models/Customer.php @@ -9,6 +9,7 @@ class CustomerModel { 'address', 'number', 'nic', + 'user_id' ]; public function registerCustomer(array $data){ diff --git a/app/views/admin/components/navbar.php b/app/views/admin/components/navbar.php index 4d047e7e..f8d0f461 100644 --- a/app/views/admin/components/navbar.php +++ b/app/views/admin/components/navbar.php @@ -11,5 +11,7 @@ -
Login
+ +
Login
+ \ No newline at end of file diff --git a/app/views/components/navbar.php b/app/views/components/navbar.php index 582d123b..3b853f6a 100644 --- a/app/views/components/navbar.php +++ b/app/views/components/navbar.php @@ -11,5 +11,57 @@ -
Login
- \ No newline at end of file + + + + +
+ profile picture + +
+ + + +
Login
+ + + + + \ No newline at end of file diff --git a/app/views/profile.view.php b/app/views/profile.view.php index 8074924b..1108340d 100644 --- a/app/views/profile.view.php +++ b/app/views/profile.view.php @@ -16,7 +16,7 @@
-
Hello Jenny!
+
@@ -26,10 +26,10 @@
-
Name : Jenny Fernando
+
Name : name ?>
-
Age : 20
+
NIC : nic ?>
Role : Customer
diff --git a/public/assets/css/style.css b/public/assets/css/style.css index f5969bba..7ec78359 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -48,6 +48,72 @@ color: #4C5039; } + + +/* nav profile avatar*/ + + +.navbar .profile-avatar { + position: relative; + display: inline-block; + margin-right: 20px; +} + +.navbar .profile-avatar img { + width: 40px; + height: 40px; + border-radius: 50%; + cursor: pointer; +} + +.navbar .dropdown-menu { + display: none; + position: absolute; + top: 60px; + right: 0; + background-color: #fff; /* Set the default background color */ + color: #4c5039; /* Set the default font color */ + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + z-index: 2; +} + +.navbar .dropdown-menu ul { + list-style: none; + padding: 0; + margin: 0; +} +/* +.navbar .dropdown-menu ul li { + padding: 10px; +} */ + +/* Style the links inside the dropdown menu */ +.navbar .dropdown-menu ul li a { + text-decoration: none; + color: #4c5039; /* Set default link color */ + transition: all 0.3s ease; /* Add smooth transition effect for all properties */ + display: block; + padding: 10px 20px ; +} + +/* Change link color and background on hover */ +.navbar .dropdown-menu ul li a:hover { + color: #6b6f55; /* Set a different color on hover */ + background-color: #f0f0f0; /* Change background color on hover */ +} + +/* Show dropdown menu on click */ +.navbar .profile-avatar.active .dropdown-menu { + display: block; +} + + + + + +/* nav profile end */ + + .section-button { background-color: #F4F4F4; color: #4C5039;