/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check()) {
         return Helpers::redirectDashboard();
     }
     return $next($request);
 }
Exemplo n.º 2
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 {
             $returnURL = array('ru' => $request->path());
             return Helpers::redirectLogin($returnURL);
         }
     }
     return $next($request);
 }
Exemplo n.º 3
0
 /**
  * @return mixed
  */
 public function getMiscDataAttribute()
 {
     return Helpers::is_serialized($this->attributes['misc_data']) ? unserialize($this->attributes['misc_data']) : $this->attributes['misc_data'];
 }
 /**
  * unserializes fields attribute on the fly before saving to database
  *
  * @return mixed
  */
 public function getFieldsAttribute()
 {
     return Helpers::is_serialized($this->attributes['fields']) ? unserialize($this->attributes['fields']) : $this->attributes['fields'];
 }
 /**
  * Log the user out of the application.
  *
  * @param Dispatcher $dispatcher
  * @return \Illuminate\Http\Response
  */
 public function getLogout(Dispatcher $dispatcher)
 {
     Auth::logout();
     $dispatcher->fire('backend.auth.logout');
     return redirect(Helpers::getLoginRoute());
 }
Exemplo n.º 6
0
 /**
  * @return mixed
  */
 public function getValueAttribute()
 {
     return Helpers::is_serialized($this->attributes['value']) ? unserialize($this->attributes['value']) : $this->attributes['value'];
 }
 /**
  * Execute the command.
  *
  * @param Content $content
  * @param Factory $validator
  * @param ContentType $contentType
  * @param Dispatcher $dispatcher
  * @param Repository $config
  * @return CommandResult
  */
 public function handle(Content $content, Factory $validator, ContentType $contentType, Dispatcher $dispatcher, Repository $config)
 {
     $content = $this->createContentModel($content, $config);
     // get content available permissions
     try {
         $cType = $contentType->findOrFail($this->contentTypeId);
         $cTypeManage = $cType->type . '.manage';
     } catch (\Exception $e) {
         return new CommandResult(false, "Invalid Content Type.", null, 400);
     }
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission([$cTypeManage])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     // validate data
     $validationResult = $validator->make(array('title' => $this->title, 'body' => $this->body, 'slug' => $this->slug, 'author_id' => $this->authorId, 'content_type_id' => $this->contentTypeId), $content::$rules);
     if ($validationResult->fails()) {
         return new CommandResult(false, $validationResult->getMessageBag()->first(), null, 400);
     }
     // prepare data to be store
     $contentToBeCreated = array('title' => $this->title, 'body' => $this->body, 'slug' => $this->slug, 'status' => Helpers::issetAndHasValueOrAssignDefault($this->status, Content::CONTENT_PUBLISHED), 'author_id' => $this->authorId, 'content_type_id' => $this->contentTypeId, 'meta' => $this->metaData, 'misc_data' => $this->miscData, 'taxonomies' => $this->taxonomies);
     // fire event creating
     $dispatcher->fire($cType->type . '.creating', array($contentToBeCreated));
     $createdContent = $content->create($contentToBeCreated);
     // taxonomy
     foreach ($contentToBeCreated['taxonomies'] as $termId => $value) {
         if ($value == true) {
             $createdContent->terms()->attach(array('content_type_taxonomy_term_id' => $termId));
         }
     }
     // meta
     foreach ($contentToBeCreated['meta'] as $formGroup => $formGroupData) {
         foreach ($formGroupData as $metaKey => $metaValue) {
             $createdContent->metaData()->create(array('key' => $metaKey, 'value' => $metaValue, 'form_group_name' => $formGroup));
         }
     }
     // fire event created
     $dispatcher->fire($cType->type . '.created', array($createdContent));
     // return response
     return new CommandResult(true, "Content successfully created.", $createdContent, 201);
 }