public function edit() { if (Request::ajax() && Request::isMethod('post')) { if (Input::has('userinfo')) { $userinfo = json_decode(Input::get('userinfo'), TRUE); if (User::find(Auth::id())->userinfo->fill($userinfo)->save()) { return json_encode(array('status' => true, 'msg' => 'Done updating user info!')); } else { return json_encode(array('msg' => 'Unable to update user info, Please Try Again')); } } elseif (Input::has('password')) { $password = json_decode(Input::get('password'), TRUE); $user = User::find(Auth::id()); if (isset($password['old_password']) && isset($password['new_password']) && Hash::check($password['old_password'], $user->password)) { $user->password = Hash::make($password['new_password']); if ($user->save()) { return json_encode(array('status' => true, 'msg' => 'Done updating password!')); } else { return json_encode(array('msg' => 'Unable to update user info, Please Try Again')); } } } } return json_encode(array('msg' => 'Unable to update user info, Please Try Again')); }
public static function getPageAction($module_id, $page_id) { $where = array('group_id' => User::find(Auth::id())->group->group_id, 'module_id' => $module_id, 'page_id' => $page_id); $permission = Permission::where($where)->get()->toArray(); if (count($permission) == 0) { App::abort(403, 'Unauthorized action.'); } return $permission[0]['action_value']; }
protected function checkPage($page_id) { if ($this->page_module) { $this->checkModule(); if (User::checkUserPages($this->page_module, $page_id)) { return; } } $this->diplayError(); }
public function index() { $this->checkModule(); $action_value = Permission::getPageAction($this->page_module, $this->page_id); $group_id = User::find(Auth::id())->group_id; if ($group_id != 1) { $this->diplayError(404); } return view('content.setting.company.company', array('action_value' => $action_value)); }
private function userList() { User::create(array('user_id' => 1, 'username' => 'Admin', 'password' => Hash::make('Admin'), 'group_id' => $this->group_id)); }
public function data() { $this->checkPageAction($this->page_id, Action::$View); if (Request::ajax()) { if (Input::has('draw') && Input::get('draw')) { $model_name = 'App\\Models\\ACL\\Group'; $data = array('tbl_company.company_name', 'tbl_group.group_name', 'tbl_group.group_name', 'tbl_group.group_name', 'tbl_group.group_id'); $joins = array('tbl_company,tbl_company.company_id,=,tbl_group.company_id,inner'); $user = User::find(Auth::id()); $company_id = $user->group->company_id; $where_raw = 'tbl_group.group_id <> 1 '; $where_array = array(); if ($company_id != 1) { $where_raw .= 'AND tbl_group.group_name <> "Admin"'; $where_array['company_id'] = $company_id; } $start = Input::get('start'); $length = Input::get('length'); $search = Input::get('search'); $order = Input::get('order'); $response = $this->filterData($model_name, $data, $start, $length, $order, $search, $joins, $where_array, $where_raw); foreach ($response['data'] as &$data) { $data['modules'] = $this->getModules($data->group_id); $data['pages'] = $this->getPages($data->group_id); } return json_encode($response); } } }
/** * @covers ::grantUserRole * @covers ::revokeUserRole * @throws \Signes\Acl\Exception\DuplicateEntry * @expectedException \Signes\Acl\Exception\DuplicateEntry */ public function testUserRoleGrantDuplicate() { $user = new User(); $user->login = '******'; $user->password = '******'; $user->group_id = '2'; $user->save(); $role = new Role(); $role->setName('TestRole')->save(); $this->repository->grantUserRole($role, $user); $this->repository->grantUserRole($role, $user); }
public static function checkUserModule($module_id) { $module_ids = array_unique(User::find(Auth::id())->group->permission->lists('module_id')); return in_array($module_id, $module_ids); }
/** * @covers ::createPermission * @covers ::grantUserPermission * @covers ::grantGroupPermission * @covers ::grantRolePermission * @covers ::grantGroupRole * @covers ::grantUserRole * @covers ::collectPermissions * @covers ::collectUserPermissions * @covers ::collectGroupPermissions * @covers ::collectRolePermission * @covers ::parseSpecialRoles * @covers ::parsePermissions * @covers ::__prepareResource * @covers ::__compareResourceWithPermissions * @covers ::isAllow */ public function testAclAreaPermission() { $group = new Group(); $group->setName('TestGroup')->save(); $role1 = new Role(); $role1->setName('TestRole1')->save(); $role2 = new Role(); $role2->setName('TestRole2')->save(); $role3 = new Role(); $role3->setName('TestRole3')->setFilter('R')->save(); $permission1 = $this->acl->createPermission('zone1', 'access1', ['act1', 'act2', 'act3'], 'Zone 1'); $permission2 = $this->acl->createPermission('zone2', 'access2', ['act1', 'act2', 'act3'], 'Zone 2'); $permission3 = $this->acl->createPermission('zone3', 'access3', ['act1', 'act2', 'act3'], 'Zone 3'); $user = new User(); $user->login = '******'; $user->password = '******'; $user->setGroup($group); $user->save(); // Connect user with permissions $this->acl->grantUserPermission($permission1, $user, ['act1'], true); $this->acl->grantUserPermission($permission2, $user, ['act1', 'act2', 'act3'], true); // Connect group with permissions $this->acl->grantGroupPermission($permission1, $group, ['act3'], true); // Connect roles with permissions $this->acl->grantRolePermission($permission3, $role1, ['act1'], true); $this->acl->grantRolePermission($permission1, $role2, ['act2'], true); $this->acl->grantRolePermission($permission2, $role3, ['act2'], true); // Connect user with roles $this->acl->grantUserRole($role2, $user, true); $this->acl->grantUserRole($role3, $user, true); // Connect group with roles $this->acl->grantGroupRole($role1, $group, true); $this->acl->grantGroupRole($role2, $group, true); $this->assertTrue($this->acl->isAllow('zone1.access1|act1.act2.act3', $user)); $this->assertTrue($this->acl->isAllow('zone2.access2|act1.act3', $user)); $this->assertTrue($this->acl->isAllow('zone3.access3|act1', $user)); // because act2 was revoked (R) $this->assertFalse($this->acl->isAllow('zone2.access2|act1.act2.act3', $user)); }
private function checkUserValidation($user_id) { $user = User::find($user_id); if (!is_null($user->brand) && count($user->brand->toArray()) != 0) { return false; } return true; }