From 1a5e6daaf899d2c77d2aebf3f15b7518a84d3e7f Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 28 Jun 2024 17:02:06 +0530 Subject: [PATCH] CHANGE_ADVERTISEMENT_JWT_CHANGE: AADHAVAN --- app/Config/Routes.php | 8 + .../AppContentManagementController.php | 96 ++++++++ app/Controllers/EmployeeRestController.php | 29 +-- app/Filters/AuthJWT.php | 50 +++-- app/Helpers/JWTToken.php | 14 +- app/Views/add_image_list.php | 210 ++++++++++++++++++ app/Views/layout/header.php | 29 +++ 7 files changed, 393 insertions(+), 43 deletions(-) create mode 100644 app/Controllers/AppContentManagementController.php create mode 100644 app/Views/add_image_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7917751a..402721b0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -10,8 +10,16 @@ use CodeIgniter\Router\RouteCollection; $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); // Reminder Mail Notification + $routes->get("reminder_mail", "NotificationController::reminder_mail"); + +$routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); +$routes->get("add_image_index", "AppContentManagementController::add_image_index"); +$routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1"); +$routes->get("frontend_content", "AppContentManagementController::frontend_content"); + + // $routes->get('/', 'LoginController::index'); $routes->get('/test', 'Home::index'); $routes->get('/login', 'LoginController::index'); ///auth/google diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php new file mode 100644 index 00000000..300036be --- /dev/null +++ b/app/Controllers/AppContentManagementController.php @@ -0,0 +1,96 @@ +myLogger = \Config\Services::mylogger(); + $this->addImgModel = new AddImgModel(); + $this->feContentModel = new FEContentModel(); + } + public function add_image_index() + { + $this->myLogger->logme('error','Addvertisement Image list function called'); + $headerData['page_name'] = 'Addvertisement Image List'; + $data['addImageList'] = $this->addImgModel->findAll(); + + // dd($data); + + echo view('layout/header', $headerData); + echo view('add_image_list', $data); + echo view('layout/footer'); + + // $this->loadLayout('client_onboarding', $data); + } + + public function add_advertise_image(){ + + // print_r($this->request->getPost());die; + $uploadFilePath = ROOTPATH . 'public/uploads/advertiseImage/'; + $file_name = file_Upload($this->request->getFile('advertise_image'), $uploadFilePath); + $data['id'] = $this->request->getPost('add_image_id'); + // $data['created_by'] = get_session_userid(); + $data['name'] = $file_name; + + if($data['id'] == 0){ + $insert = $this->addImgModel->insert($data); + if($insert){ + return $this->respond(['status' => true,'code' => 200,'data' => "success"], 200); + + }else{ + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + + } + }else{ + $id = $data['id']; + $update = $this->addImgModel->update($id,$data); + if($update){ + return $this->respond(['status' => true,'code' => 200,'data' => "success"], 200); + + }else{ + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + } + } + } + + public function getAdvertiseImage($image_id){ + + $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); + + if($image_data){ + return $image_data['name']; + }else{ + return ; + } + } + + + + // Front End Content Area + public function frontend_content(){ + + $data['test'] = $this->feContentModel->findAll(); + $headerData['page_name'] = 'Front-End Content'; + + echo view('layout/header', $headerData); + echo view('frontend_content_list', $data); + echo view('layout/footer'); + } + +} \ No newline at end of file diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index a14aac42..ef41e1b2 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -622,13 +622,7 @@ class EmployeeRestController extends AdminController // Upload the Employee Detail in DB by Sheet Data public function employeeUpload() { - - - - try { - // echo $this->request->getPost('client_id'); - // die; $file = $this->request->getFile('file'); $client_id = $this->request->getPost('client_id'); $client_branch_id = $this->request->getPost('client_branch_id'); @@ -639,17 +633,12 @@ class EmployeeRestController extends AdminController $jwt = $this->request->getHeader('Authorization'); $jwtParts = explode(' ', $jwt); - // print_r($jwtParts);die; - $token = $jwtParts[2]; - // return "hello"; - + $token = $jwtParts[2]; + $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true); // get the employee id from token $employee_id = $decodedPayload['id']; - - - $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first(); if ($client_policy) { $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); @@ -701,13 +690,13 @@ class EmployeeRestController extends AdminController $check_miss_match[]=$data[0][$i]; } } - if (count($check_miss_match) > 0) { return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Column Name's are miss Match's!", 'data'=> $check_miss_match], 200); } } if(count($data[0]) != 11){ + return json_encode($data[0]); return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200); } @@ -734,18 +723,6 @@ class EmployeeRestController extends AdminController } $dataToInsert = []; $basic_cover_si= []; - // if ($extra[9]) { - // $new_array = []; - // for ($i=0; $i < count($extra[9]); $i++) { - // if ($sum_insured_amount_for_check_employee_2 != $extra[9][$i] || $sum_insured_amount_for_check_employee_1 != $extra[9][$i]) { - // $new_array[] = $i+1; - // } - // } - // if (count($new_array) > 0) { - // $count =count($new_array); - // return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "$count Employee Sum Insured is Not Match.. " , 'data' => $new_array], 200); - // } - // } foreach ($extra['0'] as $index => $id) { $relation =''; if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') { diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index 193ad6ec..b64a2a76 100644 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -13,6 +13,7 @@ use ReflectionClass; require_once('../vendor/autoload.php'); use App\Models\EmployeeModel; +use App\Models\LevelContactModel; class AuthJWT implements FilterInterface @@ -20,7 +21,6 @@ class AuthJWT implements FilterInterface public function before(RequestInterface $request, $arguments = null) { $jwt = $request->getHeader('Authorization'); - $model = new EmployeeModel(); if ($jwt) { if (JWTToken::validateJWT($jwt)) { @@ -28,22 +28,44 @@ class AuthJWT implements FilterInterface $data = json_decode($data); $id = $data->decoded->id; - $user_data = $model->where('id', $id)->first(); + if(isset($data->decoded->emp_code)){ + $model = new EmployeeModel(); + $user_data = $model->where('id', $id)->first(); - if($user_data['token_time_out'] > time()){ - $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; - $model->update($id, $data); - return true; + if($user_data['token_time_out'] > time()){ + $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; + $model->update($id, $data); + return true; + }else{ + $data =["token_time_out" => '']; + $model->update($id, $data); + header('Content-Type: application/json'); + http_response_code(401); + // $error = json_encode(["status" => 401, "message" => $data->message]); + $error = json_encode(["status" => 401, "message" => "Token is Invalid"]); + echo $error; + exit; + } }else{ - $data =["token_time_out" => '']; - $model->update($id, $data); - header('Content-Type: application/json'); - http_response_code(401); - // $error = json_encode(["status" => 401, "message" => $data->message]); - $error = json_encode(["status" => 401, "message" => "Token is Invalid"]); - echo $error; - exit; + $model = new LevelContactModel(); + $hr_data = $model->where('id', $id)->first(); + + if($hr_data['token_time_out'] > time()){ + $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; + $model->update($id, $data); + return true; + }else{ + $data =["token_time_out" => '']; + $model->update($id, $data); + header('Content-Type: application/json'); + http_response_code(401); + // $error = json_encode(["status" => 401, "message" => $data->message]); + $error = json_encode(["status" => 401, "message" => "Token is Invalid"]); + echo $error; + exit; + } } + } } else { header('Content-Type: application/json'); diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 592c38f8..5e351c5e 100644 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -13,6 +13,7 @@ use CodeIgniter\HTTP\RequestInterface; use ReflectionClass; use App\Models\EmployeeModel; +use App\Models\LevelContactModel; class JWTToken @@ -25,13 +26,20 @@ class JWTToken try{ $token = JWT::encode($request_data ,$secret_Key,'HS512'); - - $model = new EmployeeModel(); $id = $request_data['id']; $data =[ "token_time_out" => time() + getenv('TOKENTIMEOUT') ]; - $model->update($id, $data); + if(isset($data['emp_code'])){ + $model = new EmployeeModel(); + $model->update($id, $data); + + }else{ + $models = new LevelContactModel(); + $models->update($id, $data); + + } + return $token; } diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php new file mode 100644 index 00000000..9658053d --- /dev/null +++ b/app/Views/add_image_list.php @@ -0,0 +1,210 @@ + + +
+
+
+
+
+
+

Advertisement Image List

+
+
+ ADD +
+
+ + + + + + + + + + + + + + + + + + + + +
Advertisement Image NameStatusAction
+ + + +
+
+
+
+
+ + + +
+ + + + + \ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 9c6a4795..8461b8ec 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -40,6 +40,7 @@ + /assets/css/jodit.css" rel="stylesheet" type="text/css" /> @@ -69,6 +70,8 @@ }