Beispiel #1
1
 /**
  * @param $uri
  * @param $method
  * @param array $parameters
  * @param bool $collection
  *
  * @return mixed|string
  */
 public function call($uri, $method, $parameters = [], $collection = true)
 {
     try {
         $origin_input = $this->request->input();
         $request = $this->request->create($uri, $method, $parameters);
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         $this->request->replace($origin_input);
         return $this->getResponse($dispatch, $dispatch->getContent(), $collection);
     } catch (NotFoundHttpException $e) {
         throw new NotFoundHttpException('Request Not Found.');
     }
 }
Beispiel #2
0
 /**
  * File upload trait used in controllers to upload files
  */
 public function saveFiles(Request $request)
 {
     /**
      * Get Controller Name for uploade folder
      */
     $action = app('request')->route()->getAction();
     $controller = class_basename($action['controller']);
     $controller = explode('@', $controller);
     $folder_name = strtolower(str_replace('Controller', '/', $controller[0]));
     if (!file_exists(base_path('uploads/') . $folder_name)) {
         mkdir(base_path('uploads/') . $folder_name, 0777);
         mkdir(base_path('uploads/thumb/') . $folder_name, 0777);
     }
     foreach ($request->all() as $key => $value) {
         if ($request->hasFile($key)) {
             if ($request->has($key . '_w') && $request->has($key . '_h')) {
                 // Check file width
                 $filename = $folder_name . time() . '-' . $request->file($key)->getClientOriginalName();
                 $file = $request->file($key);
                 $image = Image::make($file);
                 Image::make($file)->resize(50, 50)->save(base_path('uploads/thumb') . '/' . $filename);
                 $width = $image->width();
                 $height = $image->height();
                 if ($width > $request->{$key . '_w'} && $height > $request->{$key . '_h'}) {
                     $image->resize($request->{$key . '_w'}, $request->{$key . '_h'});
                 } elseif ($width > $request->{$key . '_w'}) {
                     $image->resize($request->{$key . '_w'}, null, function ($constraint) {
                         $constraint->aspectRatio();
                     });
                 } elseif ($height > $request->{$key . '_w'}) {
                     $image->resize(null, $request->{$key . '_h'}, function ($constraint) {
                         $constraint->aspectRatio();
                     });
                 }
                 $image->save(base_path('uploads') . '/' . $filename);
                 $request->replace(array_merge($request->all(), [$key => $filename]));
                 $request->files->remove($key);
             } else {
                 $filename = $folder_name . time() . '-' . $request->file($key)->getClientOriginalName();
                 $request->file($key)->move(base_path('uploads'), $filename);
                 $request->replace(array_merge($request->all(), [$key => $filename]));
                 $request->files->remove($key);
             }
             // Check & Delete current file
             if ($request->has($key . '_c')) {
                 $this->deleteFiles($request->{$key . '_c'});
             }
         }
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $input = $request->all();
     array_set($input, 'match.id', $request->route('matchId'));
     $request->replace($input);
     return $next($request);
 }
 /**
  * Unfallow a User
  *
  * @param $userIdToUnfallow
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($userIdToUnfallow, Request $request)
 {
     $request->replace(array_add($request->all(), 'userId', Auth::id()));
     $this->dispatcher->dispatchFrom(UnfallowUser::class, $request);
     Flash::success('You have now unfallowed this user');
     return Redirect::back();
 }
 /**
  * Replace the request input with the previous request input.
  *
  * @return void
  */
 protected function replaceRequestInput()
 {
     array_pop($this->requestStack);
     $previous = end($this->requestStack);
     $this->router->setCurrentRequest($previous);
     $this->request->replace($previous->input());
 }
Beispiel #6
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     // Parameters for GET, POST
     $parameters = $parameters ? current($parameters) : array();
     try {
         // store the original request data and route
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // replace the request input...
         $this->request->replace($request->input());
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // replace the request input and route back to the original state
         $this->request->replace($originalInput);
         $this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
     }
 }
 /** @test */
 public function it_sets_page_numbers_in_the_title()
 {
     $request = new Request();
     $request->replace(['page' => '2']);
     $meta = new MetaDataService($request);
     $meta->setMeta('Bar');
     $this->assertEquals('Bar (Page 2) - Site Name', $meta->metaTitle());
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, \Closure $next)
 {
     $input = $request->input(null, []);
     array_walk_recursive($input, function (&$val) {
         $val = trim($val);
     });
     $request->replace($input);
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if ('testing' === $this->app->environment() && $request->has('_token')) {
         $input = $request->all();
         $input['_token'] = $request->session()->token();
         // we need to update _token value to make sure we get the POST / PUT tests passed.
         Log::debug('Input token replaced (' . $input['_token'] . ').');
         $request->replace($input);
     }
     return $next($request);
 }
 /**
  * @param Request $request
  * @return \OAuth2\HttpFoundationBridge\Response
  */
 public function getOAuthToken(Request $request)
 {
     // adding the client secret into the request object
     $requestArray = $request->all();
     $requestArray['client_secret'] = env('APP_KEY');
     $request->replace($requestArray);
     $bridgedRequest = \OAuth2\HttpFoundationBridge\Request::createFromRequest($request->instance());
     $bridgedResponse = new \OAuth2\HttpFoundationBridge\Response();
     $bridgedResponse = \App::make('oauth2')->handleTokenRequest($bridgedRequest, $bridgedResponse);
     return $bridgedResponse;
 }
 /**
  * File upload trait used in controllers to upload files
  */
 public function saveFiles(Request $request)
 {
     foreach ($request->all() as $key => $value) {
         if ($request->hasFile($key)) {
             $filename = time() . '-' . $request->file($key)->getClientOriginalName();
             $request->file($key)->move(public_path('uploads'), $filename);
             $request->replace(array_merge($request->all(), [$key => $filename]));
             $request->files->remove($key);
         }
     }
 }
Beispiel #12
0
 protected function login(Request $request)
 {
     // we flash the request
     $request->flash();
     // we sanitize the entries
     $request->replace(InputSanitizer::sanitize($request->all()));
     // we set the remember to false if we do not find it
     $request->merge(['remember' => $request->get('remember', false)]);
     // we check the inputs validity
     $rules = ['email' => 'required|email', 'password' => 'required', 'remember' => 'required|boolean'];
     if (!Validation::check($request->all(), $rules)) {
         return redirect()->back();
     }
     // we try to authenticate the user
     try {
         if (!($user = Sentinel::authenticate($request->except('remember'), $request->get('remember')))) {
             Modal::alert([trans('auth.message.login.failure')], 'error');
             return redirect()->back();
         }
         // we notify the current user
         Modal::alert([trans('auth.message.login.success', ['name' => $user->first_name . " " . $user->last_name])], 'success');
         // redirect to the url stored in the session
         if ($url = session()->get('previous_url')) {
             session()->forget('previous_url');
             return redirect($url);
         } else {
             // or redirect to home
             return redirect(route('home'));
         }
     } catch (NotActivatedException $e) {
         // we log the error
         CustomLog::error($e);
         // we notify the current user
         Modal::alert([trans('auth.message.activation.failure'), trans('auth.message.activation.email.resend', ['email' => $request->get('email'), 'url' => route('account.activation_email', ['email' => $request->get('email')])])], 'error');
         return redirect()->back();
     } catch (ThrottlingException $e) {
         switch ($e->getType()) {
             case 'ip':
                 // we notify the current user
                 Modal::alert([trans('auth.message.throttle.ip', ['seconds' => $e->getDelay()])], 'error');
                 break;
             default:
                 // we notify the current user
                 Modal::alert([$e->getMessage()], 'error');
                 break;
         }
         return redirect()->back();
     } catch (Exception $e) {
         // we notify the current user
         \Modal::alert([trans('auth.message.login.error'), trans('global.message.global.failure.contact.support', ['email' => config('settings.support_email')])], 'error');
         return redirect()->back();
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // if he has a get parameter d
     if ($request->has('d')) {
         $d = Demultiplexer::getByToken($request->input('d'));
         // if demultiplexer with this token exists it replace parameter d by all parameter for the request
         if ($d->params) {
             $request->replace(json_decode($d->params, true));
         }
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  *
  * @throws \Illuminate\Session\TokenMismatchException
  */
 public function handle($request, Closure $next)
 {
     if ('testing' === App::environment() && $request->exists('_token')) {
         $input = $request->all();
         $input['_token'] = $request->session()->token();
         $request->replace($input);
     }
     if ($this->isReading($request) || $this->shouldPassThrough($request) || $this->tokensMatch($request)) {
         return $this->addCookieToResponse($request, $next($request));
     }
     throw new TokenMismatchException();
 }
Beispiel #15
0
 public function postShortcut(Request $request)
 {
     $request->replace($this->checkShortcut($request));
     if (Shortcuts::where('user_id', $request->input('user_id'))->where('name', $request->input('name'))->first()) {
         return json(error(2001));
     }
     if (Shortcuts::create($request->all())) {
         return json(['name' => $request->input('name')]);
     } else {
         return json(error(2000));
     }
 }
Beispiel #16
0
 public function postShortcut(Request $request)
 {
     $request->replace($this->checkShortcut($request));
     if (Shortcut::where('uid', $request->input('uid'))->where('name', $request->input('name'))->first()) {
         return APIdata(['error' => 2001]);
     }
     if (Shortcut::create($request->all())) {
         return APIdata(['name' => $request->input('name')]);
     } else {
         return APIdata(['error' => 2000]);
     }
 }
Beispiel #17
0
 /**
  * File upload trait used in controllers to upload files
  */
 public function saveFiles(Request $request)
 {
     if (!file_exists(public_path('uploads'))) {
         mkdir(public_path('uploads'), 0777);
         mkdir(public_path('uploads/thumb'), 0777);
     }
     foreach ($request->all() as $key => $value) {
         if ($request->hasFile($key)) {
             if ($request->has($key . '_w') && $request->has($key . '_h')) {
                 // Check file width
                 $filename = time() . '-' . $request->file($key)->getClientOriginalName();
                 $file = $request->file($key);
                 $image = Image::make($file);
                 Image::make($file)->resize(50, 50)->save(public_path('uploads/thumb') . '/' . $filename);
                 $width = $image->width();
                 $height = $image->height();
                 if ($width > $request->{$key . '_w'} && $height > $request->{$key . '_h'}) {
                     $image->resize($request->{$key . '_w'}, $request->{$key . '_h'});
                 } elseif ($width > $request->{$key . '_w'}) {
                     $image->resize($request->{$key . '_w'}, null, function ($constraint) {
                         $constraint->aspectRatio();
                     });
                 } elseif ($height > $request->{$key . '_w'}) {
                     $image->resize(null, $request->{$key . '_h'}, function ($constraint) {
                         $constraint->aspectRatio();
                     });
                 }
                 $image->save(public_path('uploads') . '/' . $filename);
                 $request->replace(array_merge($request->all(), [$key => $filename]));
                 $request->files->remove($key);
             } else {
                 $filename = time() . '-' . $request->file($key)->getClientOriginalName();
                 $request->file($key)->move(public_path('uploads'), $filename);
                 $request->replace(array_merge($request->all(), [$key => $filename]));
                 $request->files->remove($key);
             }
         }
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     //        return response()->json($request->route('token'));
     $t = DB::table('tokens')->where('token', $request->route('token'))->first();
     if ($t) {
         $input = $request->all();
         $input['userId'] = $t->userId;
         $request->replace($input);
         return $next($request);
     } else {
         return response()->json(['errorMessage' => 'token is not valid'], 403);
     }
 }
 public function saveAction(Request $request)
 {
     $params = $request->all();
     $params['day'] = Date::conversion($params['day']);
     $request->replace($params);
     unset($params['_token'], $params['q']);
     $routeBack = $request->get('redirect', false);
     if (!$routeBack) {
         $routeBack = 'hours-control.new';
         if (isset($params['id']) && (int) $params['id'] > 0) {
             $routeBack = 'hours-control.edit';
         }
     }
     if ($request->getMethod() == 'POST') {
         // saving data!
         $isValid = $this->repository->validateRequest($request);
         if (!is_bool($isValid)) {
             $request->session()->flash('message', "Invalid data, please check the following errors: ");
             $request->session()->flash('validationErrros', $isValid);
             $formattedDate = \Datetime::createFromFormat('Y-m-d', $request->get('day'));
             $request->replace(['day' => $formattedDate->format('d/m/Y')]);
             return redirect()->route($routeBack, [$routeBack == 'hours-control.edit' ? $params['id'] : null])->withInput()->with('validationErrors', $isValid);
         }
         //update
         if ($routeBack == 'hours-control.edit') {
             $hourControl = $this->repository->findById($params['id']);
             if (!$hourControl) {
                 $request->session()->flash('message', "Register [{$params['id']}] not found");
                 return redirect('hours-control');
             }
             $hourControl = HoursControl::findOrNew($params['id']);
             $hourControl->fill($params);
             $hourControl->update();
             $request->session()->flash('message', "Register [{$hourControl->task}] updated successfully!");
             $request->session()->flash('success', true);
             return redirect('hours-control');
         }
         //insert
         $hourControls = new HoursControl();
         $hourControls->create($params);
         $request->session()->flash('message', "Successfully created register");
         $request->session()->flash('success', true);
         $redirect = $request->get('redirect', false) != false ? $request->get('redirect') : 'hours-control';
         return redirect()->route($redirect);
     }
     $request->session()->flash('message', "Method not allowed");
     return redirect('hours-control');
 }
Beispiel #20
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->has('access_token')) {
         return json(error(1000));
     }
     $token = $request->input('access_token');
     $user = Crypt::decrypt($token);
     $user = (array) json_decode($user);
     if (!Cache::get('accessToken_' . $user['id'])) {
         return json(error(1000));
     }
     $all = $request->all();
     $all['_user'] = $user;
     unset($all['access_token']);
     $request->replace($all);
     return $next($request);
 }
Beispiel #21
0
 public function saveAction(Request $request)
 {
     $params = $request->all();
     $params['date'] = Date::conversion($params['date']);
     $request->replace($params);
     unset($params['_token'], $params['q']);
     $routeBack = $request->get('redirect', false);
     if (!$routeBack) {
         $routeBack = 'tasks.new';
         if (isset($params['id']) && (int) $params['id'] > 0) {
             $routeBack = 'tasks.edit';
         }
     }
     if ($request->getMethod() == 'POST') {
         // saving data!
         $isValid = $this->repository->validateRequest($request);
         if (!is_bool($isValid)) {
             $request->session()->flash('message', "Invalid data, please check the following errors: ");
             $request->session()->flash('validationErrros', $isValid);
             return redirect()->route($routeBack, [$routeBack == 'tasks.edit' ? $params['id'] : null])->withInput()->with('validationErros', $isValid);
         }
         //update
         if ($routeBack == 'tasks.edit') {
             $task = $this->repository->findById($params['id']);
             if (!$task) {
                 $request->session()->flash('message', "Task [{$params['id']}] not found");
                 return redirect('tasks');
             }
             $task = Tasks::findOrNew($params['id']);
             $task->fill($params);
             $task->update();
             $request->session()->flash('message', "Task [{$task->task}] updated successfully!");
             $request->session()->flash('success', true);
             return redirect('tasks');
         }
         //insert
         $tasks = new Tasks();
         $tasks->create($params);
         $request->session()->flash('message', "Successfully created task");
         $request->session()->flash('success', true);
         $redirect = $request->get('redirect', false) != false ? $request->get('redirect') : 'tasks';
         return redirect()->route($redirect);
     }
     $request->session()->flash('message', "Method not allowed");
     return redirect('tasks');
 }
Beispiel #22
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     if (!preg_match('/^http(s)?:/', $uri)) {
         $uri = '/' . ltrim($uri, '/');
     }
     try {
         // Store the original request data and route.
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // Masking route to allow testing with PHPUnit.
         /*if ( ! $originalRoute instanceof Route)
           {
               $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request());
           }*/
         // Create a new request to the API resource
         $request = $this->request->create($uri, strtoupper($method), $parameters);
         // Replace the request input...
         $this->request->replace($request->input());
         // Dispatch request.
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // Restore the request input and route back to the original state.
         $this->request->replace($originalInput);
         // This method have been removed from Laravel.
         //$this->router->setCurrentRoute($originalRoute);
         return $response;
     } catch (NotFoundHttpException $e) {
         //trigger_error('Not found');
         var_dump($e->getMessage());
     } catch (FatalErrorException $e) {
         var_dump($e->getMessage());
     }
 }
Beispiel #23
0
 /**
  * Call internal URI with parameters.
  *
  * @param  string $uri
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function invoke($uri, $method, $parameters = array())
 {
     // Request URI.
     $uri = '/' . ltrim($uri, '/');
     try {
         // Store the original request data and route.
         $originalInput = $this->request->input();
         $originalRoute = $this->router->getCurrentRoute();
         // Masking route to allow testing with PHPUnit.
         // if ( ! $originalRoute instanceof Route)
         // {
         //     $originalRoute = new Route(new \Symfony\Component\HttpFoundation\Request());
         // }
         $requestMethod = strtoupper($method);
         // Create a new request to the API resource
         $request = $this->request->create($uri, $requestMethod, $parameters);
         // Replace request method and input.
         $this->request->setMethod($requestMethod);
         $this->request->replace($request->input());
         // Dispatch request.
         $dispatch = $this->router->dispatch($request);
         if (method_exists($dispatch, 'getOriginalContent')) {
             $response = $dispatch->getOriginalContent();
         } else {
             $response = $dispatch->getContent();
         }
         // Decode json content.
         if ($dispatch->headers->get('content-type') == 'application/json') {
             if (function_exists('json_decode') and is_string($response)) {
                 $response = json_decode($response, true);
             }
         }
         // Restore the request input and route back to the original state.
         $this->request->replace($originalInput);
         return $response;
     } catch (NotFoundHttpException $e) {
         throw new HmvcNotFoundHttpException('Request Not Found.');
     } catch (FatalErrorException $e) {
         throw new HmvcFatalErrorException($e->getMessage());
     }
 }
Beispiel #24
0
 /**
  * Replace the input for the current request.
  *
  * @param array $input
  * @return void 
  * @static 
  */
 public static function replace($input)
 {
     \Illuminate\Http\Request::replace($input);
 }
Beispiel #25
0
 /**
  * @param $id
  * @param Request $request
  * @return mixed
  */
 public function update($id, Request $request)
 {
     // we get the image
     try {
         $image = $this->repository->find($id);
     } catch (Exception $e) {
         // we notify the current user
         Modal::alert([trans('libraries.images.message.find.failure', ['id' => $id]), trans('global.message.global.failure.contact.support', ['email' => config('settings.support_email')])], 'error');
         return redirect()->back();
     }
     // we check the current user permission
     if ($permission_denied = Permission::hasPermissionJson('libraries.images.update')) {
         return response(['message' => [$permission_denied]], 401);
     }
     // we replace the value by a slug string
     $request->merge(['value' => str_slug($request->value)]);
     // we sanitize the entries
     $request->replace(InputSanitizer::sanitize($request->all()));
     // we check the inputs validity
     $rules = ['value' => 'alpha_dash|unique:library_files,alias'];
     if (is_array($errors = Validation::check($request->all(), $rules, true))) {
         return response(['value' => $image->alias, 'message' => $errors], 401);
     }
     try {
         $image->alias = $request->value;
         $image->save();
         return response(['value' => $image->alias, 'message' => [trans('libraries.images.message.update.success', ['image' => $image->src])]], 200);
     } catch (Exception $e) {
         // we log the error
         CustomLog::error($e);
         return response(['value' => $image->alias, 'message' => [trans('libraries.images.message.update.failure', ['image' => $image->src]), trans('global.message.global.failure.contact.support', ['email' => config('settings.support_email')])]], 401);
     }
 }
 /**
  * Leave a comment
  *
  * @param  Request $request
  * @param Dispatcher $dispatcher
  * @return Response
  */
 public function store(Request $request, Dispatcher $dispatcher)
 {
     $request->replace(array_add($request->all(), 'user_id', \Auth::id()));
     $dispatcher->dispatchFrom(LeaveCommentOnStatus::class, $request);
     return \Redirect::back();
 }
Beispiel #27
0
 /**
  * Sanitize the Inputs.
  *
  */
 public function sanitizeInputs(Request $request)
 {
     $input = $request->all();
     $input['username'] = trim(filter_var($request->input('username'), FILTER_SANITIZE_STRING));
     $input['password'] = trim(filter_var($request->input('password'), FILTER_SANITIZE_STRING));
     $input['password_confirmation'] = filter_var($request->input('password_confirmation'), FILTER_SANITIZE_STRING);
     $input['firstrname'] = trim(filter_var($request->input('firstname'), FILTER_SANITIZE_STRING));
     $input['lastname'] = trim(filter_var($request->input('lastname'), FILTER_SANITIZE_STRING));
     if (isset($input['email'])) {
         $input['email'] = trim(filter_var($request->input('email'), FILTER_SANITIZE_EMAIL));
     }
     $request->replace($input);
 }
Beispiel #28
0
 /**
  * @param $id
  * @param Request $request
  * @return mixed
  */
 public function activate($id, Request $request)
 {
     // we get the news
     try {
         $news = $this->repository->find($id);
     } catch (Exception $e) {
         // we log the error
         CustomLog::error($e);
         // we notify the current user
         return response(['message' => [trans('news.message.find.failure', ['id' => $id]), trans('global.message.global.failure.contact.support', ['email' => config('settings.support_email')])]], 401);
     }
     // we check the current user permission
     if ($permission_denied = Permission::hasPermissionJson('news.update')) {
         return response(['active' => $news->active, 'message' => [$permission_denied]], 401);
     }
     if ($permission_denied = Permission::hasPermissionJson('news.activate')) {
         return response(['active' => $news->active, 'message' => [$permission_denied]], 401);
     }
     // if the active field is not given, we set it to false
     $request->merge(['active' => $request->get('active', false)]);
     // we sanitize the entries
     $request->replace(InputSanitizer::sanitize($request->all()));
     // we check inputs validity
     $rules = ['active' => 'required|boolean'];
     if (is_array($errors = Validation::check($request->all(), $rules, true))) {
         return response(['active' => $news->active, 'message' => $errors], 401);
     }
     try {
         $news->active = $request->get('active');
         $news->save();
         return response(['active' => $news->active, 'message' => [trans('news.message.activation.success.label', ['action' => trans_choice('news.message.activation.success.action', $news->active), 'news' => $news->title])]], 200);
     } catch (Exception $e) {
         // we log the error
         CustomLog::error($e);
         // we notify the current user
         return response(['active' => $news->fresh()->active, 'message' => [trans('news.message.activation.failure', ['news' => $news->title])]], 401);
     }
 }
Beispiel #29
0
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function pageUpdate(Request $request)
 {
     // we check the current user permission
     if (!Permission::hasPermission('home.page.update')) {
         // we redirect the current user to the user list if he has the required permission
         if (Sentinel::getUser()->hasAccess('home.page.view')) {
             return redirect()->route('home.page.edit');
         } else {
             // or we redirect the current user to the home page
             return redirect()->route('dashboard.index');
         }
     }
     // we sanitize the entries
     $request->replace(InputSanitizer::sanitize($request->all()));
     // we check inputs validity
     $rules = ['title' => 'required|string', 'description' => 'required|string|min:1500', 'video_link' => 'url'];
     // we check the inputs validity
     if (!Validation::check($request->all(), $rules)) {
         // we flash the request
         $request->flash();
         return redirect()->back();
     }
     try {
         // we store the content into a json file
         file_put_contents(storage_path('app/home/content.json'), json_encode($request->except('_token', '_method')));
         Modal::alert([trans('home.message.update.success')], 'success');
         return redirect()->back();
     } catch (\Exception $e) {
         // we log the error
         CustomLog::error($e);
         // we notify the current user
         Modal::alert([trans('home.message.update.failure'), trans('global.message.global.failure.contact.support', ['email' => config('settings.support_email')])], 'error');
         return redirect()->back();
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $request->replace(clean($request->all()));
     return $next($request);
 }