public function run() { DB::table('acl_group_permissions')->truncate(); DB::table('acl_groups')->truncate(); $groups = array(array('name' => 'Super Admin', 'description' => 'Super Admin Account', 'date_created' => new DateTime()), array('name' => 'Admin', 'description' => 'Admin Account', 'date_created' => new DateTime())); DB::table('acl_groups')->insert($groups); $permission = Permission::all(); $grouplist = Group::all(); foreach ($grouplist as $group) { foreach ($permission as $row) { $group_permission = new GroupPermissions(); $group_permission->permission_id = $row->id; $group_permission->group_id = $group->id; $group_permission->save(); } } $operator = array(array('name' => 'Operator', 'description' => 'Operator Account', 'date_created' => new DateTime())); DB::table('acl_groups')->insert($operator); $player = array(array('name' => 'Player', 'description' => 'Player Account', 'date_created' => new DateTime())); DB::table('acl_groups')->insert($player); $this->command->info('Group table seeded!'); }
/** * Authenticates a user. * The example implementation makes sure if the user_name and user_password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { $record = Users::model()->findByAttributes(array('user_username' => $this->username)); if (is_null($record)) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($record->user_password != $this->password) { $this->errorCode = self::ERROR_PASSWORD_INVALID; $this->errorCode = self::ERROR_USERNAME_INVALID; } else { $authPermissions = array(); if (!empty($record->user_type)) { $authPermissions = GroupPermissions::getUserGroupPermissions($record->user_type); } $userData = $record->attributes; $this->setState('data', $userData); $this->setState('auth', $authPermissions); $this->errorCode = self::ERROR_NONE; } } return !$this->errorCode; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { if (ACL::checkUserPermission('groups.edit') == false) { return Redirect::action('dashboard'); } $groupInfo = Group::find($id); $permissionList = Permission::all(); $groupPermission = GroupPermissions::where('group_id', $id)->get(); $gPermission = array(); foreach ($groupPermission as $row) { $gPermission[] = $row->permission_id; } if (!empty($groupInfo)) { $title = Lang::get('Edit Groups'); $formOpen = Form::open(array('method' => 'post', 'id' => 'form-group', 'class' => 'smart-form', 'route' => array('groups.update', $id))); $formClose = Form::close(); return View::make('groups/edit', array('groupInfo' => $groupInfo, 'permissonList' => $permissionList, 'groupPermission' => $gPermission, 'formOpen' => $formOpen, 'formClose' => $formClose, 'title' => $title)); } else { $message = 'Cannot find GroupInfo'; return Redirect::action('settings.groups')->with('error', $message); } }
/** * Get User inherited permission from group */ public static function groupUserMember($userId, $option = '') { $getUserMember = self::getUserMember($userId); $groupAccess = array(); if (count($getUserMember) > 0) { #$gAccess = GroupPermissions::with('aclPermission')->whereIn('group_id', $getUserMember)->get(); $gAccess = GroupPermissions::getGroupPermission($getUserMember); foreach ($gAccess as $row) { $permKey = explode('.', $row->perm_key); if ($row->visible == 1) { $groupAccess['nav'][$permKey[0]][] = array('id' => $row->id, 'perm_name' => $row->perm_name, 'perm_key' => $row->perm_key, 'visible' => $row->visible); } $groupAccess['access'][$row->perm_key] = array('id' => $row->id, 'perm_name' => $row->perm_name, 'perm_key' => $row->perm_key, 'visible' => $row->visible); } } return $groupAccess; }
/** * Manages all models. */ public function actionPermission($id) { $modulesObj = Modules::model(); $allModules = $modulesObj->getCommandBuilder()->createFindCommand($modulesObj->tableSchema, $modulesObj->dbCriteria)->queryAll(); $model = new GroupPermissions(); if (isset($_POST['GroupPermissions'])) { $model->deleteAll('fk_group =' . $id); foreach ($_POST['GroupPermissions'] as $post) { $post['fk_group'] = $id; $model = new GroupPermissions(); $model->attributes = $post; $model->save(); } $this->addMessage('Record updated successfully.'); $this->redirect(array('viewGroup')); } $tempDataModel = GroupPermissions::model()->findAll('fk_group =' . $id); $dataModel = array(); foreach ($tempDataModel as $tempModel) { $dataModel[$tempModel->fk_module] = $tempModel; } $this->render('permissionUpdate', array('allModules' => $allModules, 'model' => $model, 'fk_group' => $id, 'models' => $dataModel)); }