本文整理汇总了PHP中AuthItem类的典型用法代码示例。如果您正苦于以下问题:PHP AuthItem类的具体用法?PHP AuthItem怎么用?PHP AuthItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthItem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: checkAccess
public function checkAccess($item_name)
{
//Если суперпользователь, то разрешено все
if (isset(Yii::app()->user->role) && Yii::app()->user->role == AuthItem::ROLE_ROOT) {
return true;
}
$auth_item = AuthItem::model()->findByPk($item_name);
if (!$auth_item) {
Yii::log('Задача $item_name не найдена!');
return false;
}
if ($auth_item->allow_for_all) {
return true;
}
if ($auth_item->task) {
if ($auth_item->task->allow_for_all) {
return true;
} elseif (Yii::app()->user->checkAccess($auth_item->task->name)) {
return true;
}
} else {
if (Yii::app()->user->checkAccess($auth_item->name)) {
return true;
}
}
return false;
}
开发者ID:nizsheanez,项目名称:documentation,代码行数:27,代码来源:BaseController.php
示例2: actionDelete
public function actionDelete($authItemName)
{
$authItemName = trim($authItemName);
if ($authItemName == '') {
return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_NAME_EMPTY', array('message' => 'Role name is empty'));
}
$authItem = AuthItem::model()->find('name=:name', array(':name' => $authItemName));
if (!is_object($authItem)) {
return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_NOT_FOUND', array('message' => 'Role is not found'));
}
// check if this role is system role
if ($authItem->is_system == true) {
return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_CANNOT_DELETE_BECAUSE_SYSTEM', array('message' => 'Cannot delete this role as it is a system role'));
}
// check if this role is assigned to any user
$sql = 'SELECT COUNT(userid) FROM "' . SITE_ID . '_authassignment" WHERE itemname = \'' . $authItem->name . '\'';
$count = app()->db->createCommand($sql)->queryScalar();
if ($count > 0) {
return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_CANNOT_DELETE_BECAUSE_ASSIGNED', array('message' => "Cannot delete this role as it's assigned to users"));
}
// delete the role
if (!$authItem->delete()) {
return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_DELETE_FAILED', array('message' => 'Deleting the role has been failed'));
}
return $this->result = array('result' => null, 'returnCode' => 1);
}
开发者ID:hung5s,项目名称:yap,代码行数:26,代码来源:AuthItemApi.php
示例3: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return AuthItem the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model = AuthItem::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
开发者ID:nurulimamnotes,项目名称:ahadmon,代码行数:15,代码来源:AuthitemController.php
示例4: newRoleId
public static function newRoleId()
{
$rows = AuthItem::model()->FindBySql('select CAST(SUBSTRING(name,11) as SIGNED INTEGER) + 1 AS name from AuthItem where name like "rolebyuser%" order by CAST(SUBSTRING(name,11) as SIGNED INTEGER) desc limit 1');
$result = '1';
if (count((array) $rows) > 0) {
$result = $rows['name'];
}
return $result;
}
开发者ID:vovancho,项目名称:baseportal,代码行数:9,代码来源:CheckNewRoleForm.php
示例5: actionIndex
public function actionIndex()
{
$moduleId = $this->get('id', '');
$model = Module::model()->find('name = :name', array(':name' => $moduleId));
if ($model && $this->generateRoutes($moduleId)) {
$features = $this->getFeatures($moduleId);
}
$roles = AuthItem::model()->findAll('type = 2');
$this->render('index', array('model' => $model, 'features' => $features, 'roles' => $roles));
}
开发者ID:hung5s,项目名称:yap,代码行数:10,代码来源:ModulePermissionController.php
示例6: checkAccess
public function checkAccess($auth_item_name, $params = array(), $allow_caching = true)
{
return true;
if (Yii::app()->user->isRootRole()) {
return true;
}
$auth_item = AuthItem::model()->findByPk($auth_item_name);
if ($auth_item && $auth_item['allow_for_all']) {
return true;
}
return parent::checkAccess($auth_item_name, $params, $allow_caching);
}
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:12,代码来源:WebUser.php
示例7: checkName
public function checkName()
{
if ($this->isNewRecord) {
if (AuthItem::model()->exists('name=LOWER(:name)', array(':name' => strtolower($this->name)))) {
$this->addError('name', at('Sorry, That name is already in use.'));
}
} else {
if (AuthItem::model()->exists('name=LOWER(:name) AND id!=:id', array(':id' => $this->id, ':name' => strtolower($this->name)))) {
$this->addError('name', at('Sorry, That name is already in use.'));
}
}
}
开发者ID:YiiCoded,项目名称:yii-ecommerce,代码行数:12,代码来源:AuthItem.php
示例8: beforeAction
public function beforeAction($action)
{
$item_name = AuthItem::constructName(Yii::app()->controller->id, $action->id);
if (!RbacModule::isAllow($item_name)) {
$this->forbidden();
}
if (isset(Yii::app()->params->save_site_actions) && Yii::app()->params->save_site_actions) {
MainModule::saveSiteAction();
}
$this->setTitle($action);
$this->_setMetaTags($action);
return true;
}
开发者ID:nizsheanez,项目名称:alp.ru,代码行数:13,代码来源:BaseController.php
示例9: loadModel
public function loadModel($name)
{
$model = AuthItem::model()->findByAttributes(array(
'name' => $name,
'type' => CAuthItem::TYPE_ROLE
));
if (!$model)
{
$this->pageNotFound();
}
return $model;
}
开发者ID:nizsheanez,项目名称:kur.ru,代码行数:14,代码来源:RoleAdminController.php
示例10: preFilter
public function preFilter($filter_chain)
{
$item_name = AuthItem::constructName($filter_chain->action->controller->id, $filter_chain->action->id);
if (Yii::app()->user->checkAccess($item_name)) {
$filter_chain->run();
} else {
$msg = null;
if (YII_DEBUG) {
$msg = t('Зарещено!') . ' ' . t($item_name) . '<br/>';
$msg .= CHtml::link('Разрешить для роли "' . Yii::app()->user->role . '"', Yii::app()->createUrl('/rbac/task/allow', array('item_name' => $item_name)));
}
$filter_chain->action->controller->forbidden($msg);
}
}
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:14,代码来源:RbacFilter.php
示例11: actionAssignment
public function actionAssignment()
{
$model = new Authassignment();
if (isset($_POST['Authassignment'])) {
$model->attributes = $_POST['Authassignment'];
if ($model->validate()) {
//$this->saveModel($model);
//$this->redirect(array('view','itemname'=>$model->itemname, 'userid'=>$model->userid));
$auth = Yii::app()->authManager;
$auth->assign($model->itemname, $model->userid, $model->bizrule, $model->data);
}
}
$user = User::model()->findAll();
$item = AuthItem::model()->findAll(array('condition' => 'type=2'));
$this->render('assignment', array('model' => $model, 'user' => $user, 'item' => $item));
}
开发者ID:jayant06,项目名称:lukurug,代码行数:16,代码来源:DefaultController.php
示例12: getData
/**
* Загрузка данных из бд и распределение их по спискам
*/
private function getData()
{
$userAssign = CHtml::listData(AuthAssignment::model()->findAllByAttributes(['userid' => $this->user->id]), 'itemname', 'userid');
$authItems = AuthItem::model()->findAll(['order' => 'type DESC, description ASC']);
foreach ((array) $authItems as $item) {
$this->itemsGroupedByTypes[$item->type][$item->name] = $item;
$this->itemsList[$item->name] = $item;
// если проверять каждый элемент, то генерируется огромное количество запросов, но получается правильное дерево с отмеченными дочерними элементами
// созможно стоит при сохранении ролей что-то придумать
$this->permissionList[$item->name] = isset($userAssign[$item->name]);
//Yii::app()->authManager->checkAccess($item->name, $this->user->id);
}
$authItemsChild = AuthItemChild::model()->findAll();
foreach ((array) $authItemsChild as $item) {
$this->hierarchy[$item->parent][] = $item->child;
$this->wereChildren[] = $item->child;
}
}
开发者ID:alextravin,项目名称:yupe,代码行数:21,代码来源:RbacTree.php
示例13: clearOpers
/**
* 删除所有的action操作
* 写着玩的,不可随意执行,会把所有的operation删掉,并且删除这么operation和用户、角色之间的所有关系
* 但是也可以随便执行,因为AR模式在这里执行不了,提供个思路,哈哈。
*/
public function clearOpers()
{
$criteria = new CDbCriteria();
$criteria->condition = "type = 0";
$actions = AuthItem::model()->findAll($criteria);
foreach ($actions as $key => $action) {
$criteria_child = new CDbCriteria();
$criteria_child->condition = "child = '{$action->name}'";
$flag = ItemChildren::model()->deleteAll($criteria_child);
if ($flag > 0) {
if ($action->delete()) {
echo "{$action->name} delete success\n";
} else {
echo "{$action->name} delete failed\n";
}
}
}
}
开发者ID:A07110517,项目名称:Yii1.1_RouteGenerate,代码行数:23,代码来源:RoleCommand.php
示例14: checkAccess
/**
* Check if we have the access keys in the db
*
*/
public function checkAccess($operation, $params = array())
{
// First make sure we haven't already added it
// without looking in the db
$missingRoles = array();
if (Yii::app()->cache) {
$missingRoles = Yii::app()->cache->get('missing_roles');
if ($missingRoles === false) {
$missingRoles = array();
}
}
// Do we have that roles in the array
if (!in_array($operation, $missingRoles)) {
// We don't so look up the db
$roleExists = AuthItem::model()->find('name=:name', array(':name' => $operation));
if (!$roleExists) {
// Figure out the type first
if (strpos($operation, 'op_') !== false) {
$type = CAuthItem::TYPE_OPERATION;
} elseif (strpos($operation, 'task_') !== false) {
$type = CAuthItem::TYPE_TASK;
} else {
$type = CAuthItem::TYPE_ROLE;
}
// Create new auth item
Yii::app()->authManager->createAuthItem($operation, $type, $operation, null, null);
}
$missingRoles[$operation] = $operation;
// Save
if (Yii::app()->cache) {
Yii::app()->cache->set('missing_roles', $missingRoles);
}
}
// In case we are in debug mode then return true all the time
if (YII_DEBUG) {
return true;
}
// Return parent check access
return parent::checkAccess($operation, $params);
}
开发者ID:YiiCoded,项目名称:yii-ecommerce,代码行数:44,代码来源:WebUser.php
示例15: getAuthItems
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthItems()
{
return $this->hasMany(AuthItem::className(), ['rule_name' => 'name'])->from(['authItems' => Authitem::tableName()]);
}
开发者ID:vovancho,项目名称:yii2test,代码行数:7,代码来源:Authrule.php
示例16: actionCreateAction
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreateAction()
{
$model = new AuthItem();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['AuthItem'])) {
$model->attributes = $_POST['AuthItem'];
if ($model->save()) {
$this->logAudit("Action " . $model->name . " was created ");
$this->redirect(array('view', 'id' => $model->name));
}
}
$this->render('createAction', array('model' => $model));
}
开发者ID:robertgunze,项目名称:eams,代码行数:18,代码来源:AuthItemController.php
示例17: getModulesTasks
protected function getModulesTasks()
{
$tasks = array();
$modules = AppManager::getModulesNames();
foreach ($modules as $module_name => $module_desc) {
$operations = array();
$module_actions = AppManager::getModuleActions(ucfirst($module_name) . 'Module');
foreach ($module_actions as $controller => $actions) {
$prefix = str_replace('Controller', '', $controller);
foreach ($actions as $name => $description) {
$name = $prefix . '_' . $name;
$exists = AuthItem::model()->exists(" name = '{$name}' AND type = '" . CAuthItem::TYPE_OPERATION . "'");
$operations[] = array('name' => $name, 'description' => $description, 'exists' => $exists);
}
}
$exists = AuthItem::model()->exists(" name = '{$module_name}' AND type = '" . CAuthItem::TYPE_TASK . "'");
$tasks[] = array('exists' => $exists, 'name' => $module_name, 'description' => $module_desc, 'operations' => $operations);
}
return $tasks;
}
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:20,代码来源:TaskAdminController.php
示例18: actionTest1
function actionTest1()
{
$criteria = new CDbCriteria();
$criteria->select = array('name', 'description');
$criteria->with = array('authassignments' => array('select' => array('itemname', 'IF(name = itemname,true,false) AS Checked'), 'joinType' => 'LEFT JOIN', 'on' => 'itemname = name and userid = :userid', 'params' => array(':userid' => '1')));
$criteria->condition = 'type = 2';
// $rows = AuthItem::model()->with(array('authassignments'=>array('together'=>false)))->FindAll();
// $rows = AuthAssignment::model()->with('users','authitems','authitems.authitemchildren')->FindAll();
// $rows = User::model()->with('authitems')->FindAll();
$rows = AuthItem::model()->with('authassignments')->FindAll();
// var_dump($rows[1]['authassignments']);
$connection = Yii::app()->db;
$sql = 'SELECT ai.NAME,
ai.description,
itemname,
IF (ai.NAME = itemname,true,false) AS Checked
FROM AuthItemChild RIGHT JOIN AuthItem ai ON parent = NAME LEFT JOIN AuthAssignment ON itemname = ai.NAME AND userid = 1 WHERE (
NOT parent IN (
SELECT b.child
FROM AuthItemChild b
)
OR (parent IS NULL)
)
AND ai.type = 2
GROUP BY ai.NAME
ORDER BY ai.NAME';
$command = $connection->createCommand();
$command->select(['NAME', 'description', 'itemname', 'IF (NAME = itemname,true,false) AS Checked'])->from(['AuthItem'])->leftJoin('AuthItemChild', 'parent = NAME')->leftJoin('AuthAssignment', ['and', 'itemname = NAME', 'userid = :userid'], [':userid' => '1'])->andWhere('not parent in (SELECT b.child FROM AuthItemChild b ) OR (parent IS NULL)')->andWhere('type=:type', [':type' => '2'])->group(['NAME'])->order(['NAME']);
var_dump($command->join);
var_dump($command->params);
//var_dump($command->pdoStatement->getColumnMeta(0));
$rows = [];
$rows = $command->queryAll();
var_dump($command->pdoStatement);
// var_dump($rows);
// Print Rows
if (count((array) $rows) > 0) {
echo '<table style="border-collapse: collapse;"><tbody>';
echo '<tr>';
foreach (array_keys($rows[0]) as $field) {
echo '<th style="padding: 5px; border: 1px solid black; min-width: 50px;">' . $field . '</th>';
}
echo '</tr>';
foreach ($rows as $row) {
echo '<tr>';
foreach ($row as $cell) {
echo '<td style="padding: 5px; border: 1px solid black; min-width: 50px;">' . $cell . '</td>';
}
echo '</tr>';
}
echo '</tbody></table>';
} else {
echo 'empty rows';
}
/* if (count((array) $rows) > 0) {
echo '<table style="border-collapse: collapse;"><tbody>';
echo '<tr>';
foreach (array_keys($rows[0]->attributes) as $field)
echo '<th style="padding: 5px; border: 1px solid black; min-width: 50px;">' . $field . '</th>';
echo '</tr>';
foreach ($rows as $row) {
echo '<tr>';
foreach ($row->attributes as $cell)
echo '<td style="padding: 5px; border: 1px solid black; min-width: 50px;">' . $cell . '</td>';
echo '</tr>';
}
echo '</tbody></table>';
} else
echo 'empty rows'; */
}
开发者ID:vovancho,项目名称:baseportal,代码行数:70,代码来源:AuthItemManagerController.php
示例19: array
<?php
$roles = AuthItem::model()->findAllByAttributes(array('type' => CAuthItem::TYPE_ROLE));
return array('activeForm' => array('id' => 'user-form', 'enableAjaxValidation' => true, 'clientOptions' => array('validateOnSubmit' => true)), 'elements' => array('email' => array('type' => 'text'), 'name' => array('type' => 'text'), 'birthdate' => array('type' => 'date'), 'gender' => array('type' => 'dropdownlist', 'items' => User::$gender_options), 'about_self' => array('type' => 'textarea'), 'photo' => array('type' => 'file'), 'status' => array('type' => 'dropdownlist', 'items' => User::$status_options), 'role' => array('type' => 'dropdownlist', 'items' => CHtml::listData($roles, 'name', 'description')), 'password' => array('type' => 'password'), 'password_c' => array('type' => 'password')), 'buttons' => array('submit' => array('type' => 'submit', 'value' => 'сохранить')));
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:4,代码来源:UserForm.php
示例20: actionAddItemChild
/**
* adding auth item child relationships
*/
public function actionAddItemChild()
{
// Check Access
checkAccessThrowException('op_permission_add_item_child');
$model = new AuthItemChild();
$roles = AuthItem::model()->findAll(array('order' => 'type DESC, name ASC'));
$_roles = array();
if (count($roles)) {
foreach ($roles as $role) {
$_roles[AuthItem::model()->types[$role->type]][$role->name] = $role->description . ' (' . $role->name . ')';
}
}
// Did we choose a parent already?
if (isset($_GET['parent']) && $_GET['parent'] != '') {
$model->parent = $_GET['parent'];
}
if (isset($_POST['AuthItemChild'])) {
if (isset($_POST['AuthItemChild']['child']) && count($_POST['AuthItemChild']['child'])) {
// We need to delete all child items selected up until now
$existsalready = AuthItemChild::model()->findAll('parent=:parent', array(':parent' => $model->parent));
if (count($existsalready)) {
foreach ($existsalready as $existitem) {
Yii::app()->authManager->removeItemChild($existitem->parent, $existitem->child);
}
}
$added = 0;
foreach ($_POST['AuthItemChild']['child'] as $childItem) {
$model->child = $childItem;
if ($model->validate()) {
$added++;
}
}
// Get model parent
$authItem = AuthItem::model()->find('name=:name', array(':name' => $model->parent));
fok(at('{number} Child item(s) Added.', array('{number}' => $added)));
// Log Message
alog(at("Added {number} child items for {name}", array('{number}' => $added, '{name}' => $model->parent)));
if ($authItem) {
$this->redirect(array('view', 'id' => $authItem->id, '#' => 'tabs-2'));
} else {
$this->redirect(array('index'));
}
}
}
// Selected values
$selected = AuthItemChild::model()->findAll('parent=:parent', array(':parent' => $model->parent));
$_selected = array();
if (count($selected)) {
foreach ($selected as $select) {
$_selected[] = $select->child;
}
}
$model->child = $_selected;
// Add Breadcrumb
$this->addBreadCrumb(at('Adding Child Permissions'));
$this->title[] = at('Adding Child Permissions');
$this->render('child_form', array('model' => $model, 'roles' => $_roles));
}
开发者ID:qhyabdoel,项目名称:hris_mujigae,代码行数:61,代码来源:PermissionController.php
注:本文中的AuthItem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论