[ 'displayErrorDetails' => true, ], ]; $c = new \Slim\Container($configuration); $app = new \Slim\App($c); //$app->config('debug', true); $app->add(new JwtAuthentication([ "secret" => 'secret', "secure" => false, "rules" => [ new RequestPathRule([ "path" => ["/dashboardEndTripList","/getRoutesList","/getVehicleDriverCustomerList","/addTrip","/getTrip","/getExpenseCategory","/addExpense","/addFuelExpense","/searchRouteList","/fuelTrackList"], "passthrough" => ["/login","/public"] ]) ], "callback" => function ($request,$response,$args) use ($app) { $app->jwt = $args["decoded"]; //echo'
';print_r($args);echo'
';exit; } ])); $app->post("/public", function ($request,$response,$args) use ($app) { $dashboard = new Dashboard($app); $dashboard->getDashboard(); // exit; $data = array("message"=>" success","data"=>"Secured Content"); echo json_encode($data); return $response; }); $app->get("/dashboardEndTripList", function ($request,$response,$args) use ($app) { $dashboard = new Dashboard($app->jwt); $response = $dashboard->dashboardEndTripList(); return $response; }); $app->get("/getRoutesList", function ($request,$response,$args) use ($app) { //echo'
';print_r($app->jwt);echo'
';exit; $trip = new Trip($app->jwt); $response = $trip->getRoutes(); return $response; }); $app->get("/dashboardCountList", function ($request,$response,$args) use ($app) { $dashboard = new Dashboard($app->jwt); $response = $dashboard->dashboardAllCountList(true); return $response; }); $app->get("/getVehicleDriverCustomerList", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $getResponse = isset($get['response'])?$get['response']:''; $trip = new Trip($app->jwt); $response = $trip->getVehicleDriverCustomerData($getResponse); return $response; }); $app->get("/addTrip", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $trip = new Trip($app->jwt); $response = $trip->tripForm($get); return $response; }); $app->get("/getExpenseCategory", function ($request,$response,$args) use ($app) { $trip = new Expense($app->jwt); $response = $trip->getExpenseCategory(); return $response; }); $app->get("/getTrip", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $trip = new Expense($app->jwt); $response = $trip->getTripList($get); return $response; }); $app->get("/addExpense", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $trip = new Expense($app->jwt); $response = $trip->addExpenseRequest($get); return $response; }); $app->get("/addFuelExpense", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $trip = new Expense($app->jwt); $response = $trip->addFuelExpenseRequest($get); return $response; }); $app->get("/searchRouteList", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $trip = new Trip($app->jwt); $response = $trip->routeListData($get); return $response; }); $app->get("/fuelTrackList", function ($request,$response,$args) use ($app) { $get = $request->getParams(); $trip = new Trip($app->jwt); $response = $trip->fuelTrackData($get); return $response; }); $app->post("/login", function ($request,$response,$args) use ($app) { $post = $request->getParams(); if($post['email'] =='' && $post['password'] == ''){ $data = array("message"=>" error","data"=>"Unable to process email or password missing"); return json_encode($data); } $sql = "SELECT * FROM tbl_admin as TU WHERE TU.admin_email=:email AND TU.admin_password=:password"; $password = sha1($post['password']); try { $db = getDB(); $stmt = $db->prepare($sql); $stmt->bindParam("email", $post['email']); $stmt->bindParam("password", $password); $stmt->execute(); $updates = $stmt->fetch(PDO::FETCH_OBJ); if(!$updates){ $data = array("message"=>" error","data"=>"Invalid useremail or Password"); return json_encode($data); } /* Here generate and return JWT to the client. */ $signer = new Sha256(); $token = (new Builder())->setIssuer('http://resico@fleetvu.in') // Configures the issuer (iss claim) ->setAudience('mobileApp') // Configures the audience (aud claim) ->setId($updates->id, true) // Configures the id (jti claim), replicating as a header item ->setIssuedAt(time()) // Configures the time that the token was issue (iat claim) // ->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim) // ->setExpiration(time() + 120) // Configures the expiration time of the token (exp claim) ->set('user_id', $updates->id) // Configures a new claim, called "uid" ->set('scope', array('read','write','delete')) // Configures a new claim, called "uid" ->sign($signer, 'secret') // creates a signature using "testing" as key ->getToken(); // Retrieves the generated token if($updates->access == "Admin") { $data = array("message"=>"success","access_token"=>"".$token,"user_detail"=>$updates); } if($updates->access == "User") { $currentDate = date('Y-m-d'); //print_r($currentDate); die; $id = $updates->user_id; $sqlQuery = "SELECT * FROM tbl_trip WHERE trip_driver=:id AND date_format(str_to_date(trip_departure,'%m/%d/%Y'),'%Y-%m-%d')=:date"; $db = getDB(); $stmt = $db->prepare($sqlQuery); $stmt->bindParam("id", $id); $stmt->bindParam("date", $currentDate); $stmt->execute(); $trips = $stmt->fetch(PDO::FETCH_OBJ); //print_r($trips); die; if(!$trips){ $data = array("message"=>" error","data"=>"You have no trips for today's date"); return json_encode($data); } $data = array("message"=>"success","access_token"=>"".$token,"user_detail"=>$updates,"user_trip_details"=>$trips); } return json_encode($data); } catch(PDOException $e) { return '{"error":{"text":'. $e->getMessage() .'}}'; }catch(Exception $e) { return '{"error":{"text":'. $e->getMessage() .'}}'; } }); $app->run(); ?>