Example #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $token = !Input::get('token') ? $request['token'] : Input::get('token');
     if ($token == "gokigoks" || Handler::check($token)) {
         return $next($request)->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With')->header('Access-Control-Max-Age', '28800');
     }
     if (!$token) {
         return $next($request)->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With')->header('Access-Control-Max-Age', '28800');
     }
     return response()->json('web token invalid..', 403)->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With')->header('Access-Control-Max-Age', '28800');
 }
 /**
  * clear session. deletes user assigned web token
  * @param $request
  * @return Response
  */
 public function logout(Request $request)
 {
     $token = $request['token'];
     //if(Auth::check()) return response()->json('nka login lage ka?', 200);
     if (!$token) {
         return response()->json('empty token', 400);
     }
     //dd(UserSessionHandler::getByToken($token), \Session::all());
     if (UserSessionHandler::check($token)) {
         Auth::logout();
         UserSessionHandler::logout($token);
         return response()->json('user logged out..', 200);
     } else {
         return response()->json('invalid token to be logged out!', 401);
     }
 }
 public function addStop(Request $request)
 {
     $stop_data = $request->input('stop');
     $transpo_data = $request->input('transpo');
     $token = $request->input('token');
     $stop = new Stop();
     $stop->place_name = $stop_data['place_name'];
     $stop->details = $stop_data['stop_details'];
     $stop->price = $stop_data['price'];
     $stop->lat = $stop_data['lat'];
     $stop->lng = $stop_data['lng'];
     UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo_data, $stop);
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     //        return $current_iterinary;s
     if ($current_iterinary['err'] == 'err') {
         return response()->json($current_iterinary, 403);
     }
     $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $stop->save();
     $stop->activity()->save($activity);
     return response()->json($stop);
 }
 public static function addOtherActivity($token, $other_data, $transpo)
 {
     $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $other_data);
     //        return response()->json($response);
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $other_activity = new OtherActivity();
     $other_activity->name = $other_data['place_name'];
     $other_activity->lng = $other_data['lng'];
     $other_activity->lat = $other_data['lat'];
     $other_activity->review = $other_data['review'];
     $other_activity->expense = $other_data['expense'];
     //        return response()->json($eat);
     $other_activity->save();
     $other_activity->activity()->save($activity);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
 }
 public function addHotelTest(Request $request)
 {
     $request = $request->all();
     $food_data = $request['hotel'];
     $token = $request['token'];
     $transpo = $request['transpo'];
     $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $food_data);
     //        return response()->json($response);
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $hotel = new Hotel();
     $hotel->hotel_name = $food_data['place_name'];
     $hotel->lng = $food_data['lng'];
     $hotel->lat = $food_data['lat'];
     $hotel->tips = $food_data['review'];
     $hotel->price = $food_data['price'];
     $hotel->pic_url = '';
     //        return response()->json($eat);
     $hotel->save();
     $hotel->activity()->save($activity);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
 }
 public function addPhotoToIterinary()
 {
     $data = Input::get('image');
     $token = Input::get('token');
     //get the base-64 from data
     $iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $photo = new IterinaryPhoto();
     //decode base64 string
     //        $image =  base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
     $img = str_replace('data:image/png;base64,', '', $data);
     $img = str_replace(' ', '+', $img);
     $data = base64_decode($img);
     $png_url = str_random(16) . ".png";
     $photo->image_path = 'http://localhost:8000/api/img/' . $png_url;
     $path = public_path('images/' . $png_url);
     $result = file_put_contents($path, $data);
     $iterinary->photos()->save($photo);
     // $result = file_put_contents($path, $image);
     $response = array('status' => 'success', 'data' => $result);
     return response()->json($response);
 }