示例#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');
 }
示例#2
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;
 }
示例#3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $deletedUsers = ModelFactory::getInstance('User')->onlyTrashed()->get();
     foreach ($deletedUsers as $user) {
         $user->email = $user->email . '.deleted';
         if ($user->username) {
             $user->username = $user->username . '.deleted';
         }
         $user->save();
     }
 }
示例#4
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');
 }
示例#5
0
 /**
  * Loads the necessary data for the class
  */
 protected function prepare()
 {
     if (app('session')->has('menu_list')) {
         $this->menuList = app('session')->pull('menu_list');
     } elseif (\Auth::user()) {
         $userId = \Auth::user()->id;
         $userModel = ModelFactory::getInstance('User');
         $user = $userModel->with('group.navigations.navitems')->find($userId);
         $this->menuList = $user->group->navigations->toArray();
         // store this to session so that we'll just pull the data from session
         // and no longer need to Query again
         app('session')->put('menu_list', $this->menuList);
     }
     $this->prepared = true;
 }
示例#6
0
 /**
  * Reset user password
  * @param Request $request
  */
 public function resetPassword(Request $request)
 {
     $user = ModelFactory::getInstance('User')->where('email', '=', $request->get('email'))->first();
     $this->validate($request, ['email' => 'required|max:255']);
     if (!$user) {
         return redirect('/forgotpass')->withInput($request->only('email'))->withErrors(['error' => 'Invalid email.']);
     }
     $newPass = str_random(10);
     $user->password = bcrypt($newPass);
     $user->save();
     $data = ['name' => $user->fullname ? $user->fullname : $user->id, 'from' => config('system.from'), 'password' => $newPass];
     $email = $user->email;
     \Mail::send('emails.forgot_password', $data, function ($m) use($email) {
         $m->from(config('system.from_email'), config('system.from'));
         $m->to($email)->subject('Forgot Password');
     });
     return redirect('/login')->with('successMsg', 'New password has been send to your email.');
 }
示例#7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $email = config('system.reset_password_recipients');
     if ($email) {
         $newPassword = str_random(15);
         $user = ModelFactory::getInstance('User')->find(1);
         if ($user) {
             $user->password = bcrypt($newPassword);
             if ($user->save()) {
                 $email = explode(',', $email);
                 $data['password'] = $newPassword;
                 $data['from'] = config('system.from');
                 \Mail::send('emails.reset_password', $data, function ($m) use($email) {
                     $m->from(config('system.from_email'), config('system.from'));
                     $m->to($email)->subject('Reset Password');
                 });
             }
         }
     }
 }
示例#8
0
 /**
  * Get user info
  * @param number $userId
  * @return Ambigous <\Illuminate\View\View, \Illuminate\Contracts\View\Factory>
  */
 public function getUser($userId)
 {
     $user = ModelFactory::getInstance('User')->find($userId);
     $data = $user ? $user->toArray() : [];
     return response()->json($data);
 }
示例#9
0
 /**
  * Remove user roles from user
  * @param unknown $userId
  * @param unknown $roleId
  */
 public function removeUserRoles($userId)
 {
     return ModelFactory::getInstance('UserToRole')->where('user_id', '=', $userId)->delete();
 }
示例#10
0
 /**
  * Perform view action access check
  * @param unknown $rowId
  */
 protected function performViewAccessCheck($rowId)
 {
     return ModelFactory::getInstance('User')->where('id', '=', $rowId)->first();
 }
示例#11
0
 /**
  * Validate authorization header
  * @return boolean
  */
 public function validateAuthHeader()
 {
     if (!isset($_SERVER['HTTP_AUTHORIZATION'])) {
         return false;
     }
     $token = str_replace(config('system.authorization_prefix'), '', $_SERVER['HTTP_AUTHORIZATION']);
     if ($token) {
         $user = ModelFactory::getInstance('UserSessions')->with(['user' => function ($query) {
             $query->select('id');
         }])->where('session_string', '=', trim($token))->first(['id', 'user_pk_id']);
         if (!$user || !isset($user->user)) {
             return false;
         }
         WebService::$userId = $user->user_pk_id;
     }
     return true;
 }
示例#12
0
 /**
  * Remove all the navs belong to this role
  * @param unknown $roleId
  */
 public function removeAllFeaturesFromRole($roleId)
 {
     $roleToFeatures = ModelFactory::getInstance('RoleToFeature')->with('feature')->where('role_id', '=', $roleId)->get();
     foreach ($roleToFeatures as $roleToFeature) {
         if (!$roleToFeature->feature->system) {
             $roleToFeature->delete();
         }
     }
 }
 /**
  * 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;
 }
示例#14
0
 /**
  * This will return an Area code of a specific customer.
  * @param $customer
  * @param bool $isName
  * @return mixed
  * @internal param $customerCode
  */
 public function getCustomerAreaCode($customer, $isName = false)
 {
     $code = ModelFactory::getInstance('AppCustomer');
     if ($isName) {
         $code = $code->where('customer_name', $customer)->select('area_code')->first();
     } else {
         $code = $code->where('customer_code', $customer)->select('area_code')->first();
     }
     return $code;
 }
示例#15
0
 /**
  * Remove all the navs belong to this role
  * @param unknown $roleId
  */
 public function removeAllNavsFromRole($roleId, $protected = true)
 {
     $excepIds = $this->getProtectedMenus()->lists('id');
     $roleNavs = ModelFactory::getInstance('RoleToNav')->where('role_id', '=', $roleId)->get();
     foreach ($roleNavs as $nav) {
         if (in_array($nav->navigation_id, $excepIds->toArray()) && $protected) {
             continue;
         }
         $nav->delete();
     }
 }
示例#16
0
 /**
  * Check if user has access
  * @param unknown $name
  */
 public function hasPageAccess($name)
 {
     $groupId = auth()->user()->user_group_id;
     $navId = ModelFactory::getInstance('Navigation')->where('name', $name)->first()->id;
     return ModelFactory::getInstance('UserGroupToNav')->where('navigation_id', $navId)->where('user_group_id', $groupId)->exists();
 }
示例#17
0
 /**
  * Dectivate user
  *
  * @return Response
  */
 public function delete($id)
 {
     $user = ModelFactory::getInstance('User')->find($id);
     if ($user) {
         $user->status = 'D';
         $deletedEmail = $user->email . '.deleted';
         $count = ModelFactory::getInstance('User')->onlyTrashed()->where('email', 'like', $deletedEmail . '%')->count();
         $user->email = !$count ? $deletedEmail : $deletedEmail . ($count + 1);
         $deletedUsername = $user->username . '.deleted';
         $count = ModelFactory::getInstance('User')->onlyTrashed()->where('username', 'like', $deletedUsername . '%')->count();
         if ($user->name) {
             $user->username = !$count ? $deletedUsername : $deletedUsername . ($count + 1);
         }
         $user->save();
         $user->delete();
     }
     $response['success'] = true;
     return response()->json($response);
 }