Esempio n. 1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // Using factory
     // Getting an instance of a model User example
     $user = ModelFactory::getInstance('User');
     // Getting an instance of a Library String
     $stringLib = LibraryFactory::getInstance('String');
     // Getting an instance of a Filter DateRange
     $dateRange = FilterFactory::getInstance('DateRange');
     // Getting an instance of a Type User
     $userType = TypeFactory::getInstance('User');
     // Perform an access check
     AccessCheckFactory::getInstance('User')->canAccess(auth()->user()->id, 'view');
     // Using facade
     // Getting an instance of a model User example
     $user = \Model::getInstance('User');
     // Getting an instance of a Library String
     $stringLib = \Library::getInstance('String');
     // Getting an instance of a Filter DateRange
     $dateRange = \Filter::getInstance('DateRange');
     // Getting an instance of a Type User
     $userType = \Type::getInstance('User');
     // Passing data to view example
     $this->view->fullname = auth()->user()->fullname;
     // Perform an access check
     \AccessCheck::getInstance('User')->canAccess(1, 'view');
     return $this->view('dashboard');
 }
Esempio n. 2
0
 /**
  * Loads the necessary data for the class
  */
 protected function prepare()
 {
     $userId = auth()->user() ? auth()->user()->id : 0;
     if (!$userId) {
         $this->menuList = [];
         return;
     }
     $user = ModelFactory::getInstance('User')->with(['roles' => function ($query) {
         $query->select(['role.id']);
     }, 'roles.navigations' => function ($query) {
         $query->select(['navigation.id']);
     }])->find($userId, ['id']);
     $navIds = [];
     foreach ($user->roles as $role) {
         foreach ($role->navigations as $nav) {
             $navIds[] = $nav->id;
         }
     }
     $nav = ModelFactory::getInstance('Navigation');
     $treeLib = LibraryFactory::getInstance('DataTree', $nav, 'parent_id');
     $treeLib->addSort('order');
     $treeLib->addwhereIn('id', $navIds);
     $navs = $treeLib->getData();
     $this->menuList = $navs;
     $this->prepared = true;
 }
Esempio n. 3
0
 /**
  * Loads the necessary data for the class
  */
 protected function prepare()
 {
     if (\Session::has('menu_list')) {
         $this->menuList = app('session')->pull('menu_list');
     } elseif (\Auth::user()) {
         $userId = \Auth::user()->id;
         $user = ModelFactory::getInstance('User')->with(['group' => function ($query) {
             $query->select(['user_group.id']);
         }, 'group.navigations' => function ($query) {
             $query->select(['navigation.id']);
         }])->find($userId, ['user.id', 'user.user_group_id']);
         $navIds = [];
         foreach ($user->group->navigations as $nav) {
             $navIds[] = $nav->id;
         }
         $nav = ModelFactory::getInstance('Navigation');
         $treeLib = LibraryFactory::getInstance('DataTree', $nav, 'parent_id');
         $treeLib->addSort('order');
         $treeLib->addwhereIn('id', $navIds);
         $navs = $treeLib->getData();
         $this->menuList = $navs;
         // store this to session so that we'll just pull the data from session
         // and no longer need to Query again
         \Session::put('menu_list', $this->menuList);
     }
     $this->prepared = true;
 }
Esempio n. 4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $lib = LibraryFactory::getInstance('Sync');
     $this->info('Synchronization started at ' . date('Y-m-d H:m:s'));
     if ($lib->sync(true)) {
         $this->info('Synchronization finished at ' . date('Y-m-d H:m:s'));
     } else {
         $this->error('Synchronization failed!');
     }
 }
Esempio n. 5
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // Getting an instance of a model User example
     $user = ModelFactory::getInstance('User');
     // Getting an instance of a Library String
     $stringLib = LibraryFactory::getInstance('String');
     // Getting an instance of a Filter DateRange
     $dateRange = FilterFactory::getInstance('DateRange');
     // Getting an instance of a Type User
     $userType = TypeFactory::getInstance('User');
     // Passing data to view example
     $this->view->fullname = auth()->user()->firstname . ' ' . auth()->user()->lastname;
     return $this->view('dashboard');
 }
Esempio n. 6
0
 /**
  * This is a helper method which will handle necessary data
  * needed for the view. This is created to centralize this functionality
  * for all presenters
  * @param string $template
  * @param array $data
  * @param string $parent
  */
 protected function view($template, $data = [], $parent = '')
 {
     if ($parent) {
         $name = $parent;
     } else {
         $namespace = get_class($this);
         $chunks = explode('\\', $namespace);
         $name = array_pop($chunks);
         $name = str_replace(PresenterFactory::getSuffix(), '', $name);
     }
     $menu = LibraryFactory::getInstance('Menu')->getMyMenus();
     $this->view->menu = $menu;
     $templateName = $name . '.' . $template;
     return view($templateName, $data, (array) $this->view);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!LibraryFactory::getInstance('Permission')->hasPageAccess(request()->getRequestUri())) {
         //Check if user group is deleted and no feature at all
         // Log this user out or else it will cause limbo
         $canAccess = false;
         $userRoles = LibraryFactory::getInstance('Role')->getRoles(auth()->user()->id);
         if ($userRoles->isEmpty()) {
             // logout user
             \Auth::logout();
             session()->flush();
             return redirect('/')->with('error', 'Unauthorized Access.');
         }
         return back()->with('error', 'Unauthorized Access.');
     }
     return $next($request);
 }
Esempio n. 8
0
 /**
  * This is a helper method which will handle necessary data
  * needed for the view. This is created to centralize this functionality
  * for all presenters
  * @param string $template
  * @param array $data
  * @param string $parent
  */
 protected function view($template, $data = [], $parent = '')
 {
     if ($parent) {
         $name = $parent;
     } else {
         $namespace = get_class($this);
         $chunks = explode('\\', $namespace);
         $name = array_pop($chunks);
         $name = str_replace(PresenterFactory::getSuffix(), '', $name);
     }
     $menuLib = LibraryFactory::getInstance('Menu');
     if (!$menuLib->isActionAllowed($template)) {
         return view('errors.403');
     }
     $this->view->menu = $menuLib->getMyMenus();
     $templateName = $name . '.' . $template;
     $this->view->isAdmin = $this->isAdmin();
     $this->view->isAuditor = $this->isAuditor();
     $this->view->isAccounting = $this->isAcounting();
     $this->view->isGuest1 = $this->isGuest1();
     $this->view->isGuest2 = $this->isGuest2();
     return view($templateName, $data, (array) $this->view);
 }
Esempio n. 9
0
 /**
  * Sync reports from SFA db
  * @return \Illuminate\Http\JsonResponse
  */
 public function sync()
 {
     $result = LibraryFactory::getInstance('Sync')->sync();
     $data['logs'] = $result ? true : '';
     return response()->json($data);
 }
Esempio n. 10
0
 /**
  * Check whether the user/role has this feature
  * @param unknown $value
  * @param number $userId
  * @return unknown
  */
 function feature_enabled($value, $userId = 0)
 {
     return LibraryFactory::getInstance('Feature')->userHasFeature([$value]);
 }
Esempio n. 11
0
 /**
  * Check whether the role has this feature
  * @param unknown $roleId
  */
 public function roleHasFeature($roleId)
 {
     return LibraryFactory::getInstance('Feature')->roleHasFeatureById($roleId, $this->id);
 }
Esempio n. 12
0
 /**
  * Check if a specific user has access to this page
  * @param unknown $page The nav Id or url
  * @param number $userId The userId
  */
 public function hasPageAccess($page, $userId = 0)
 {
     $hasAccess = false;
     if (!$userId) {
         $userId = auth()->user() ? auth()->user()->id : 0;
     }
     $navModel = ModelFactory::getInstance('Navigation');
     if (is_numeric($page)) {
         $nav = $navModel->find($id);
     } else {
         $nav = $navModel->where('url', '=', $page)->first();
     }
     if ($nav) {
         // Check user permission first
         // 			$userToNav = ModelFactory::getInstance('UserToNav')
         // 							->where('user_id','=',$userId)
         // 							->where('nav_id','=',$nav->id)
         // 							->first();
         // 			if($userToNav)
         // 			{
         // 				return $userToNav->enable;
         // 			}
         // Check role permission
         $userRoles = ModelFactory::getInstance('User')->with('roles')->find($userId);
         $roleIds = [];
         foreach ($userRoles->roles as $role) {
             $roleIds[] = $role->id;
         }
         //@TODO: optimize this
         $menuLib = LibraryFactory::getInstance('Menu');
         foreach ($roleIds as $roleId) {
             if ($menuLib->roleHasMenu($roleId, $nav->id)) {
                 return true;
             }
         }
         return $hasAccess;
     }
     // Finally check feature
     if (!$hasAccess) {
         $route = request()->route();
         $action = $route->getAction();
         $controller = $action['controller'];
         $namespace = $action['namespace'];
         if ($controller && $namespace) {
             $controller = str_replace($namespace . '\\', '', $controller);
             $chunks = explode('@', $controller);
             $presenter = $chunks[0];
             $method = $chunks[1];
             if (false !== strpos(PresenterFactory::getNamespace(), $namespace)) {
                 $name = str_replace(PresenterFactory::getSuffix(), '', $presenter);
                 $permissions = PresenterFactory::getInstance($name)->getPermissions();
             } elseif (false !== strpos(ControllerFactory::getNamespace(), $namespace)) {
                 $name = str_replace(ControllerFactory::getSuffix(), '', $presenter);
                 $permissions = ControllerFactory::getInstance($name)->getPermissions();
             } elseif (false !== strpos(WebServiceFactory::getNamespace(), $namespace)) {
                 $name = str_replace(WebServiceFactory::getSuffix(), '', $presenter);
                 $permissions = WebServiceFactory::getInstance($name)->getPermissions();
             }
             if (isset($permissions[$method])) {
                 $features = $permissions[$method];
                 if (!$features || feature_enabled($features)) {
                     return true;
                 }
             } else {
                 foreach ($permissions as $method => $features) {
                     if (!$features || feature_enabled($features)) {
                         return true;
                     }
                 }
             }
         }
     }
     return $hasAccess;
 }
Esempio n. 13
0
 public function roleHasNav($roleId)
 {
     return LibraryFactory::getInstance('Menu')->roleHasMenu($roleId, $this->id);
 }