Beispiel #1
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     // 404 page when a model is not found
     if ($e instanceof ModelNotFoundException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado'], 404);
         }
         return response()->view('errors.404', [], 404);
     }
     if ($this->isHttpException($e)) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado!'], 404);
         }
         return $this->renderHttpException($e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             if ($request->ajax() || $request->wantsJson()) {
                 return response()->json(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
             }
             return response()->view('errors.500', [], 500);
         }
         return parent::render($request, $e);
     }
 }
Beispiel #2
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $role, $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('login');
         }
     }
     if (user($guard)->new && config('user.verify_email')) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect('verify');
         }
     }
     if (!user($guard)->active && config('user.verify_email')) {
         throw new InvalidAccountException('Account is not active.');
     }
     $roles = explode('|', $role);
     if (!user($guard)->hasRoles($roles)) {
         throw new RolesDeniedException($roles);
     }
     return $next($request);
 }
Beispiel #3
0
 public function store(Request $request)
 {
     $user = Sentinel::getUser();
     if ($user->id !== intval($request->uid)) {
         $rules = ['uid' => 'required|numeric|exists:users,id|min:1', 'score' => 'required|numeric'];
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             if ($request->ajax()) {
                 return response()->json(['result' => false]);
             } else {
                 return back()->withInput()->withErrors($validator);
             }
         } else {
             # Create Resume
             $rate = new Rate();
             $rate->score = intval($request->score);
             $rate->to_user_id = intval($request->uid);
             # Redirect on Success
             if ($user->rates()->save($rate)) {
                 if ($request->ajax()) {
                     $userprofile = Sentinel::findById($rate->to_user_id);
                     return response()->json(['result' => false, 'score' => $userprofile->profileRates()->avg('score')]);
                 } else {
                     return redirect()->route('user.show', ['user' => $rate->to_user_id])->with('success', 'امتیاز شما با موفقیت ثبت شد.');
                 }
             }
         }
     }
     if ($request->ajax()) {
         return response()->json(['result' => false]);
     } else {
         return back()->withInput()->with('fail', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.');
     }
 }
Beispiel #4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->route('auth.signin');
         }
     } else {
         $user = $this->auth->user();
         if ($user->ban) {
             if ($request->ajax()) {
                 return response('Unauthorized.', 401);
             } else {
                 $this->auth->logout();
                 notify()->flash('Banned', 'error', ['text' => $user->ban_reason]);
                 return redirect()->route('auth.signin');
             }
         }
     }
     /*$ipInfo = getIpInfo($request->getClientIp());
       if($ipInfo){
           if(isset($ipInfo['timezone'])){
               if($ipInfo['timezone'] != $this->auth->user()->timezone){
                   $this->auth->user()->update([
                       'timezone' => $ipInfo['timezone']
                   ]);
               }
           }
       }*/
     return $next($request);
 }
Beispiel #5
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @param  string $role
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     switch ($role) {
         case 'admin':
             if (!$request->user()->is_admin) {
                 if ($request->ajax()) {
                     return response('Access Denied')->setStatusCode(403);
                 }
                 abort(404);
             }
             break;
         case 'moderator':
             if (!$request->user()->is_moderator) {
                 if ($request->ajax()) {
                     return response('Access Denied')->setStatusCode(403);
                 }
                 abort(404);
             }
             break;
         default:
             return response('Access Denied')->setStatusCode(403);
             break;
     }
     return $next($request);
 }
Beispiel #6
0
 public function anyUpload(InterfaceFileStorage $userFileStorage, AmqpWrapper $amqpWrapper, Server $server, UploadEntity $uploadEntity)
 {
     /* @var \App\Components\UserFileStorage $userFileStorage */
     $responseVariables = ['uploadStatus' => false, 'storageErrors' => [], 'uploadEntities' => []];
     if ($this->request->isMethod('post') && $this->request->hasFile('file') && $this->request->file('file')->isValid()) {
         $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-user-files-to-storage' . DIRECTORY_SEPARATOR;
         $tmpFilePath = $tmpDir . $this->request->file('file')->getClientOriginalName();
         $this->request->file('file')->move($tmpDir, $this->request->file('file')->getClientOriginalName());
         $userFileStorage->setValidationRules($this->config->get('storage.userfile.validation'));
         $newStorageFile = $userFileStorage->addFile($tmpFilePath);
         if ($newStorageFile && !$userFileStorage->hasErrors()) {
             /* @var \SplFileInfo $newStorageFile */
             // AMQP send $newfile, to servers
             foreach ($server->all() as $server) {
                 if (count($server->configs) > 0) {
                     foreach ($server->configs as $config) {
                         // Send server and file info to upload queue task
                         $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $config->auth . '@' . $server->host . '/' . trim($config->path, '\\/')]));
                     }
                 } else {
                     // The server has no configuration
                     $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $server->host]));
                 }
             }
             $responseVariables['uploadStatus'] = true;
         } else {
             $responseVariables['storageErrors'] = $userFileStorage->getErrors();
         }
         if ($this->request->ajax()) {
             return $this->response->json($responseVariables);
         }
     }
     $responseVariables['uploadEntities'] = $uploadEntity->limit(self::UPLOAD_ENTITIES_LIMIT)->orderBy('created_at', 'DESC')->get();
     return $this->view->make('upload.index', $responseVariables);
 }
Beispiel #7
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // If the user isn't logged in or they are part of a different city
     // deny access, otherwise go for it. Might be worth adding a message to
     // explain what happened on redirect.
     $city = City::findByIATA($request->route()->getParameter('city'))->first();
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Notification::error('You need to be logged in to view that.');
             return redirect()->guest('auth/login');
         }
     } else {
         if ($city && $this->auth->user()->city_id !== $city->id) {
             Notification::error('You don\'t have permissions for that city.');
             if ($request->ajax()) {
                 return response('Unauthorized.', 401);
             } else {
                 return redirect('/' . $city->iata);
             }
         }
     }
     return $next($request);
 }
Beispiel #8
0
 public function addAddress(Request $request)
 {
     $user = Sentinel::getUser();
     $rules = ['address' => 'min:10'];
     $validator = Validator::make($request->all(), $rules);
     $result = 2;
     $id = 'address' . $result;
     if ($validator->fails()) {
         if ($request->ajax()) {
             return response()->json(['result' => false]);
         } else {
             return back()->withInput()->withErrors($validator);
         }
     }
     if (!$user->address2) {
         $user->address2 = $request->input('new');
     } else {
         $user->address3 = $request->input('new');
         $result = 3;
         $id = 'address' . $result;
     }
     if ($user->save()) {
         if ($request->ajax()) {
             return response()->json(['result' => $user->{$id}, 'aid' => $result]);
         } else {
             return back()->with('success', 'آدرس جدید اضافه شد.');
         }
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $siteID = $request->route('sites');
     $site = \App\Models\Site::find($siteID);
     // normal and admin users accessing other site info
     if (\Auth::user()->super == "No") {
         if (\Auth::user()->site_id != $siteID) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     // if super user is trying to access a site belonging to another company
     if (\Auth::user()->super == "Yes") {
         if (\Auth::user()->site->company_id != $site->company_id) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 403);
         } else {
             return redirect()->guest('auth/login');
         }
     }
     if (!$request->user()->isAdmin() && $request->user()->cannot('dashboard_view')) {
         $this->auth->logout();
         return redirect()->guest('auth/login')->withErrors(trans('messages.permission_denied'));
     }
     $route_array = explode('.', $request->route()->getName());
     $permission_name = array_search($route_array[2], array_dot($this->permission_fields));
     if ($permission_name) {
         $route_array[2] = explode('.', $permission_name)[0];
     }
     // $route_name = implode('_', $route_array);
     $route_name = $route_array[1] . '_' . $route_array[2];
     if (!$request->user()->isAdmin() && $request->user()->cannot($route_name)) {
         //PATCH 为null
         if ($request->ajax()) {
             return response()->json(['status' => trans('messages.permission_denied'), 'type' => 'error', 'code' => 403]);
         } else {
             return view('errors.403');
         }
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // First make sure there is an active session
     // dd(debug_print_backtrace(2));
     // dd(Sentry::check());
     if (!Sentry::check()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest(route('sentinel.login'));
         }
     }
     // Now check to see if the current user has the 'admin' permission
     // dd(get_class(Sentry::getUser()));
     // dd(Sentry::getUser()->hasAccess('admin'));//Sentinel\Models\User
     if (!Sentry::getUser()->hasAccess('admin')) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Session::flash('error', trans('Sentinel::users.noaccess'));
             return redirect()->route('sentinel.login');
         }
     }
     // dd(Sentry::getUser()->hasAccess('admin'));
     // dd(Sentry::getId());
     // dd(Sentry::getGroups());
     // All clear - we are good to move forward
     return $next($request);
 }
 /**
  * Gets the item edit page / information
  *
  * @param string		$modelName
  * @param mixed			$itemId
  */
 public function item($modelName, $itemId = 0)
 {
     $config = app('itemconfig');
     $fieldFactory = app('admin_field_factory');
     $actionFactory = app('admin_action_factory');
     $columnFactory = app('admin_column_factory');
     $actionPermissions = $actionFactory->getActionPermissions();
     $fields = $fieldFactory->getEditFields();
     //if it's ajax, we just return the item information as json
     if ($this->request->ajax()) {
         //try to get the object
         $model = $config->getModel($itemId, $fields, $columnFactory->getIncludedColumns($fields));
         if ($model->exists) {
             $model = $config->updateModel($model, $fieldFactory, $actionFactory);
         }
         $response = $actionPermissions['view'] ? response()->json($model) : response()->json(array('success' => false, 'errors' => "You do not have permission to view this item"));
         //set the Vary : Accept header to avoid the browser caching the json response
         return $response->header('Vary', 'Accept');
     } else {
         $view = view("administrator::index", array('itemId' => $itemId));
         //set the layout content and title
         $this->layout->content = $view;
         return $this->layout;
     }
 }
 /**
  * Show the login form
  *
  * @return mixed
  */
 public function getIndex()
 {
     if ($this->request->ajax()) {
         $this->session->forget('url.intended');
     }
     return View::make('auth.login');
 }
 /**
  * @param User $modelUser
  * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
  */
 public function girls(User $modelUser)
 {
     $registered = $modelUser->getGirls();
     if ($this->request->ajax()) {
         return response()->json(view('inc_users', ['registered' => $registered, 'message' => 'Всего зарегистрировано девушек'])->render());
     }
     return view('registered', ['registered' => $registered, 'message' => 'Всего зарегистрировано девушек']);
 }
Beispiel #15
0
 /**
  * __construct.
  *
  * @method __construct
  *
  * @param  array                                        $config
  * @param  \Illuminate\Http\Request                     $request
  * @param  \Illuminate\Contracts\Foundation\Application $app
  */
 public function __construct($config, Request $request = null, Application $app = null)
 {
     $this->request = is_null($request) === true ? Request::capture() : $request;
     $this->ajax = $this->request->ajax();
     $this->app = $app;
     $this->accepts = Arr::get($config, 'accepts', []);
     $this->showBar = Arr::get($config, 'showBar', false);
     $this->initializeTracyDebuger($config);
     $this->loadPanels($config);
 }
 public function getAutoCompleteWordsAjax(Request $request)
 {
     if (!$request->ajax()) {
         return response()->json(['response' => 'reject', 'msg' => 'request Not Allowed', 'searchWord' => $request->searchWord, 'language' => $request->languageName, 'Ajax' => $request->ajax(), 'Request' => $request->method()]);
     }
     $searchWord = $request->searchWord;
     $languageId = Language::where('id', '=', $request->languageId)->value('id');
     $Words = Word::where('language_id', '=', $languageId)->where('word', 'LIKE', $searchWord . '%')->orderBy('word', 'asc')->limit(10)->get();
     return $Words;
 }
Beispiel #17
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $cfgGoogle = \Session::get('_ClientGoogle');
     if (isset($cfgGoogle)) {
         $data = $request->all();
         if ($data['type_doc'] == 'gdoc') {
             $service = new \Google_Service_Drive($cfgGoogle);
             $file = new \Google_Service_Drive_DriveFile();
             $file->setTitle($data['name']);
             $file->setMimeType('application/vnd.google-apps.document');
             $file_rst = $service->files->insert($file);
             $data['id_doc'] = $file_rst->id;
             $data['alternateLink'] = $file_rst->alternateLink;
             $data['embedLink'] = $file_rst->embedLink;
             $rstDoc = new \App\Doc($data);
             $rstDoc->save();
             if ($request->ajax()) {
                 return response()->json(array('status' => true, 'data' => 'successful created doc by Google', 'info' => $data));
             }
         } elseif ($data['type_doc'] == 'gspreadsheets') {
             $service = new \Google_Service_Drive($cfgGoogle);
             $file = new \Google_Service_Drive_DriveFile();
             $file->setTitle($data['name']);
             $file->setMimeType('application/vnd.google-apps.spreadsheet');
             $file_rst = $service->files->insert($file);
             $data['id_doc'] = $file_rst->id;
             $data['alternateLink'] = $file_rst->alternateLink;
             $data['embedLink'] = $file_rst->embedLink;
             $rstDoc = new \App\Doc($data);
             $rstDoc->save();
             if ($request->ajax()) {
                 return response()->json(array('status' => true, 'data' => 'successful created doc by Google', 'info' => $data));
             }
         } elseif ($data['type_doc'] == 'gpresentation') {
             $service = new \Google_Service_Drive($cfgGoogle);
             $file = new \Google_Service_Drive_DriveFile();
             $file->setTitle($data['name']);
             $file->setMimeType('application/vnd.google-apps.presentation');
             $file_rst = $service->files->insert($file);
             $data['id_doc'] = $file_rst->id;
             $data['alternateLink'] = $file_rst->alternateLink;
             $data['embedLink'] = $file_rst->embedLink;
             $rstDoc = new \App\Doc($data);
             $rstDoc->save();
             if ($request->ajax()) {
                 return response()->json(array('status' => true, 'data' => 'successful created doc by Google', 'info' => $data));
             }
         }
     } else {
         if ($request->ajax()) {
             return response()->json(array('status' => false, 'data' => 'For sync calendar is need login with Google!'));
         }
     }
 }
Beispiel #18
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         return redirect('/');
     }
     if ($e instanceof MethodNotAllowedHttpException) {
         return redirect('/');
     }
     if ($e instanceof NotFoundHttpException) {
         return response(view('errors.404'), 404);
     }
     if ($e instanceof InvalidConfirmationCodeException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect('/');
     }
     if ($e instanceof UserNotOwnerOfProjectException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project'));
     }
     if ($e instanceof ProjectCompletedException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project'));
     }
     if ($e instanceof UserRequiresAuthenticationException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['login' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.login')]);
         } else {
             Session::flash('flash_message', $e->getMessage());
             return redirect('/');
         }
     }
     if ($e instanceof UserHasIncompleteProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['incomplete' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.incomplete')]);
         }
     }
     if ($e instanceof UserAlreadyHasSubmittedProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['pendingProject' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.pending-project')]);
         }
     }
     if ($e instanceof UserHasCurrentLiveProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['liveProject' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.live-project')]);
         }
     }
     if ($e instanceof ProjectNameAlreadyTakenException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['duplicateName' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.duplicate-name')]);
         }
     }
     return parent::render($request, $e);
 }
Beispiel #19
0
 public function store(Request $request)
 {
     if ($request->ajax()) {
         parse_str($request->data, $input);
     } else {
         $input = $request->all();
     }
     $rules = ['fullname' => 'required|farsi|min:3|max:150', 'email' => 'required|email|min:5|max:150', 'tel' => 'required|digits_between:8,15', 'des' => 'required|min:10|max:500'];
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         if ($request->ajax()) {
             return response()->json(['result' => 'error', 'errors' => $validator->errors()]);
         } else {
             return back()->withInput()->withErrors($validator);
         }
     } else {
         $supportticket = Support::where('ip', $request->ip())->whereRaw('UTC_TIMESTAMP() <= TIMESTAMP(created_at + INTERVAL ' . config('app.support_throttle') . ')')->count();
         if ($supportticket > 0) {
             if ($request->ajax()) {
                 return response()->json(['result' => 'wait']);
             } else {
                 return redirect()->home()->with('fail', 'شما لحظاتی پیش یک پیام با موفقیت ارسال کرده اید، لطفا بعدا تلاش کنید.');
             }
         } else {
             # Create Support
             $support = new Support();
             $support->fullname = $input['fullname'];
             $support->email = $input['email'];
             $support->tel = $input['tel'];
             $support->description = $input['des'];
             $support->ip = $request->ip();
             # Redirect on Success
             if ($support->save()) {
                 Mail::send('emails.support', ['support' => $support], function ($message) use($support) {
                     $message->from(config('app.info_email'), 'کامت');
                     $message->sender(config('app.info_email'), 'کامت');
                     $message->to($support->email, $support->fullname)->subject('گروه طراحی و توسعه کامت');
                     $message->replyTo(config('app.support_email'), 'کامت');
                 });
                 if ($request->ajax()) {
                     return response()->json(['result' => 'success']);
                 } else {
                     return redirect()->home()->with('success', 'پیام شما با موفقیت ثبت شد.');
                 }
             }
         }
     }
     if ($request->ajax()) {
         return response()->json(['result' => 'fail']);
     } else {
         return back()->withInput()->with('fail', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.');
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $toolID = $request->route('tools');
     $tool = \App\Models\Tool::find($toolID);
     $toolType = \App\Models\Tool::find($toolID)->type;
     $userID = \App\Models\Tool::find($toolID)->user_id;
     // any user trying to access personal tools
     if ($toolType == "Personal") {
         if (\Auth::user()->id != $userID) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     // any user trying to access company tools
     if ($toolType == "Company") {
         // if a user is not an admin or a super
         if (\Auth::user()->admin == "No" && \Auth::user()->super == "No") {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
         // if an admin user is trying to access a company tool that does not belong to their site
         if (\Auth::user()->admin == "Yes") {
             if (\Auth::user()->site_id != $tool->user->site_id) {
                 if ($request->ajax()) {
                     return response('Unauthorized', 401);
                 } else {
                     return redirect()->guest('noAccess');
                 }
             }
         }
         // if a super user is trying to access a company tool that does not belong to their company
         if (\Auth::user()->super == "Yes") {
             if (\Auth::user()->site->company_id != $tool->user->site->company_id) {
                 if ($request->ajax()) {
                     return response('Unauthorized', 401);
                 } else {
                     return redirect()->guest('noAccess');
                 }
             }
         }
     }
     // end of $toolType == "Company" if statement
     return $next($request);
 }
Beispiel #21
0
 /**
  * Update the specified resource in storage.
  *
  * @param Request $request
  * @param int     $id
  *
  * @return Response
  */
 public function update(Page $page, $templateblock, Widgetnode $widgetnode, Request $request)
 {
     if ($request->has('config')) {
         $widgetnode->config = $request->get('config');
         $widgetnode->save();
     }
     if ($request->ajax() && $request->has('title')) {
         $widgetnode->title = $request->get('title');
         $widgetnode->save();
     }
     if (!$request->ajax()) {
         return back();
     }
 }
 public function deleteIndex(Request $request)
 {
     $model = $this->executeFunction('findOrFail', $request->input('id'));
     if ($model->delete()) {
         if ($request->ajax()) {
             return response()->json(['mensaje' => 'Se borró el ' . call_user_func([$model, 'getPrettyName']) . ' correctamente.']);
         }
         return redirect($this->getFolder(false, true))->with('mensaje', 'Se borró el ' . call_user_func([$model, 'getPrettyName']) . ' correctamente.');
     }
     if ($request->ajax()) {
         return response()->json(['errores' => $model->getErrors()]);
     }
     return redirect($this->getFolder(false, true))->withErrors($model->getErrors());
 }
Beispiel #23
0
 public function store(Request $request)
 {
     $cfgGoogle = \Session::get('_ClientGoogle');
     if (isset($cfgGoogle)) {
         $user = \Auth::user();
         $data = $request->all();
         //dd($data);
         $rArtifacts = \App\Methodology::Join('phases', function ($join) {
             $join->on('phases.id_methodology', '=', 'methodologies.id');
         })->join('artifacts', function ($join) {
             $join->on('artifacts.id_phase', '=', 'phases.id');
         })->select('methodologies.id as meth_id', 'methodologies.name as meth_name', 'phases.id as pha_id', 'phases.name as pha_name', 'artifacts.id as art_id', 'artifacts.name as art_name', 'artifacts.start as art_start', 'artifacts.delivery as art_delivery')->where('artifacts.active', true)->where('phases.active', true)->where('methodologies.active', true)->where('methodologies.id', $data['id_methodology'])->orderBy('artifacts.delivery', 'asce')->get();
         //dd($user);
         $eventCreate = array();
         $calendarGoogle = new \Google_Service_Calendar($cfgGoogle);
         foreach ($rArtifacts as $key => $artifact) {
             $start = date("c", strtotime($artifact->art_start));
             $end = date("c", strtotime($artifact->art_delivery));
             $event = new \Google_Service_Calendar_Event(array('summary' => $artifact->art_name, 'description' => $artifact->art_name, 'start' => array('dateTime' => $start, 'timeZone' => 'America/Mexico_City'), 'end' => array('dateTime' => $end, 'timeZone' => 'America/Mexico_City')));
             //dd($user->id);
             $table['id_student'] = $user->id;
             $table['id_period'] = intval($data['id_period']);
             $table['id_company'] = intval($data['id_company']);
             $table['id_methodology'] = $artifact->meth_id;
             //dd($artifact->pha_id);
             $table['id_phase'] = intval($artifact->pha_id);
             $table['id_artifact'] = intval($artifact->art_id);
             $table['name'] = $artifact->art_name;
             $table['start'] = $artifact->art_start;
             $table['delivery'] = $artifact->art_delivery;
             //	$artifact_current  = \App\Artifact::find(intval($artifact->art_id));
             //	dd($artifact_current);
             $calendarId = 'primary';
             $events = $calendarGoogle->events->insert($calendarId, $event);
             $table['id_calendar'] = $events->id;
             $table['htmlLink'] = $events->htmlLink;
             $tpmCal = new \App\Calendar($table);
             $tpmCal->save();
         }
         if ($request->ajax()) {
             return response()->json(array('status' => true, 'data' => 'The syn calendar is successful!'));
         }
     } else {
         if ($request->ajax()) {
             return response()->json(array('status' => false, 'data' => 'For sync calendar is need login with Google!'));
         }
     }
     //dd($data_calendar);
 }
Beispiel #24
0
 /**
  * @param User $modelUser
  * @param Salary $modelSalary
  * @param Subordination $modelSub
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
  */
 public function index(User $modelUser, Salary $modelSalary, Subordination $modelSub)
 {
     $users = $modelUser->getUsers();
     if ($this->request->ajax() && $this->request->has('id')) {
         $id = $this->request->get('id');
         $salary = $modelSalary->getSalary($id);
         $average = $modelSalary->getAverage($id);
         return response()->json(view('inc_payment_report', ['salary' => $salary, 'average' => $average])->render());
     }
     if ($this->request->ajax() && $this->request->has('subordination')) {
         $people = $modelSub->getSubordinate($this->request->get('subordination'));
         return response()->json(view('inc_subordination_report', ['people' => $people])->render());
     }
     return view('welcome', ['users' => $users]);
 }
 public function index(Request $request)
 {
     if ($request->ajax()) {
         $reminders = PaymentDefaultReminder::all();
         return response()->json($reminders);
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     // Check for the guard and redirect accordingly
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } elseif ($guard == 'student') {
             return redirect()->guest('/students/login');
         } elseif ($guard == 'teacher') {
             return redirect()->guest('/teachers/login');
         } elseif ($guard == 'hostelStaff') {
             return redirect()->guest('/hostelStaffs/login');
         } elseif ($guard == 'libraryStaff') {
             return redirect()->guest('/libraryStaffs/login');
         } elseif ($guard == 'departmentStaff') {
             return redirect()->guest('/departmentStaffs/login');
         } elseif ($guard == 'chiefWardenStaff') {
             return redirect()->guest('/chiefWardenStaffs/login');
         } elseif ($guard == 'adminStaff') {
             return redirect()->guest('/adminStaffs/login');
         } elseif ($guard == 'admin') {
             return redirect()->guest('/admins/login');
         }
     }
     return $next($request);
 }
 /**
  * @param Request $request
  *
  * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 protected function createDefaultResponse($request)
 {
     if ($request->ajax()) {
         return response('', 200);
     }
     return redirect()->route('blog.admin.categories.index');
 }
 public function update($id, $permission_type, Request $request)
 {
     if ($id <= 1) {
         return \Redirect::back();
     }
     $params = array_keys(\Request::route()->parameters());
     $permissions = $request->all();
     if (strpos($permission_type, 'management') === false) {
         $provider = $this->permissionsProvider;
     } else {
         $provider = $this->permissionManagementProvider;
     }
     $response = null;
     $type = $params[0];
     if (empty($permissions['action_id'])) {
         $response = call_user_func([$provider, sprintf('add%sPermission', ucfirst($type))], $id, $permissions['action_admin_id']);
         $message = 'add';
     } else {
         call_user_func([$provider, sprintf('remove%sPermission', ucfirst($type))], $id, $permissions['action_admin_id']);
         $message = 'del';
         $response = $permissions['action_id'];
     }
     \Event::fire(new PermissionUpdated($permission_type, $id));
     if ($request->ajax()) {
         return \Response::json(['response' => $response, 'message' => $message]);
     } else {
         \Flash::successUpdate();
         return back();
     }
 }
 public function store(Request $request)
 {
     //Seteo la zona horaria
     date_default_timezone_set('America/Argentina/Buenos_Aires');
     if ($request->ajax()) {
         $persona_registrada = DB::select('select * from personas WHERE  documento like "' . $request->username . '"');
         $personas = DB::select('select * FROM personas p1 INNER JOIN evento_persona t2 ON p1.id = t2.persona_id WHERE  p1.documento like "' . $request->username . '"' . ' and t2.evento_id = ' . $request->evento_id);
         if (!empty($personas) && is_array($personas)) {
             //verifico que el array tenga datos
             if ($this->validarAsistencias($personas, $request->evento_id)) {
                 //valido cantidad maxima de asistencias
                 if ($this->validarUltimoIngreso($personas, $request->evento_id)) {
                     //valido tolerancia
                     $this->insertAsistencia($personas);
                     //inserto asistencias
                 }
             }
             array_push($personas, ["valor" => Config::get('constant.MENSAJE')]);
             return response()->json($personas);
         } else {
             if (empty($persona_registrada)) {
                 array_push($personas, ["valor" => Config::get('constant.MENSAJE_ERROR')]);
             } else {
                 array_push($personas, ["valor" => Config::get('constant.MENSAJE_NO_PERTENECE_EVENTO')]);
             }
             return response()->json($personas);
         }
     }
 }
Beispiel #30
0
 public function index(Request $request)
 {
     //Input::get('active')
     $sort = Input::get('sort') == null ? 'id' : Input::get('sort');
     $sortDirection = Input::get('sortDirection') == null ? 'DESC' : Input::get('sortDirection');
     $tariffs = Tariff::orderBy($sort, $sortDirection);
     if (Input::has('deactive')) {
         if (Input::has('active')) {
             $tariffs = $tariffs->get();
         } else {
             $tariffs = $tariffs->where('active', '=', false);
             $tariffs = $tariffs->get();
         }
     } else {
         if (Input::has('active')) {
             $tariffs = $tariffs->where('active', '=', true);
             $tariffs = $tariffs->get();
         }
     }
     if ($request->ajax()) {
         return view('tariffs.indexAjax', ['tariffs' => $tariffs]);
     } else {
         return view('tariffs.index', ['tariffs' => $tariffs]);
     }
 }