示例#1
0
 public function actionRegister()
 {
     $model = new AuthItem();
     if (Yii::$app->request->isPost) {
         $routes = Yii::$app->request->post('routes');
         if (!empty($routes) && is_array($routes)) {
             $auth = Yii::$app->authManager;
             foreach ($routes as $route) {
                 $oldPermission = $auth->getPermission($route);
                 if (empty($oldPermission)) {
                     $role = $auth->createPermission($route);
                     $auth->add($role);
                 }
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data route(s) has been successfully saved'));
             return $this->redirect(['register']);
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data route(s) failed to save'));
         }
     }
     $routers = RouterGenerator::run();
     ksort($routers);
     $registeredRouters = AuthItem::find()->where(['like', 'name', '/'])->andWhere(['type' => 2])->all();
     return $this->render('create-existing', ['model' => $model, 'routers' => $routers, 'registeredRouters' => $registeredRouters]);
 }
示例#2
0
 /**
  * Lists all AuthItem models.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $query = AuthItem::find();
     $config = ['pageSize' => Yii::$app->params['pageSize'], 'where' => ['type' => 1]];
     $locals = YiiForum::getPagedRows($query, $config);
     return $this->render('/role/index', $locals);
 }
示例#3
0
 public static function getRoles()
 {
     $condition = '';
     if (\Yii::$app->user->identity->role != 'Superadmin') {
         $condition = ' AND name != "Superadmin"';
     }
     return AuthItem::find()->where('type =:type' . $condition, [':type' => self::TYPE_ROLE])->all();
 }
示例#4
0
 /**
  * Lists all AuthItem models.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $groups = YiiForum::getAppParam('cachedPermissionsGroup');
     $query = AuthItem::find();
     $config = ['pageSize' => Yii::$app->params['pageSize'], 'order' => 'created_at DESC', 'where' => ['type' => 2]];
     $locals = YiiForum::getPagedRows($query, $config);
     $locals['groups'] = $groups;
     return $this->render('index', $locals);
 }
示例#5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['type' => 1])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['not like', 'name', '/']);
     return $dataProvider;
 }
 public function actionSignup()
 {
     $model = new SignupForm();
     $authItems = AuthItem::find()->all();
     if ($model->load(Yii::$app->request->post())) {
         if ($user = $model->signup()) {
             if (Yii::$app->getUser()->login($user)) {
                 return $this->goHome();
             }
         }
     }
     return $this->render('signup', ['model' => $model, 'authItems' => $authItems]);
 }
示例#7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['type' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['type' => $this->type, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'rule_name', $this->rule_name])->andFilterWhere(['like', 'data', $this->data]);
     return $dataProvider;
 }
示例#8
0
 /**
  * 授权
  * @return [type] [description]
  */
 public function actionAuth()
 {
     $this->layout = false;
     $auth = Yii::$app->authManager;
     if (Yii::$app->request->post()) {
         $zu_id = Yii::$app->request->post('item_zu_id');
         $zu_model = $this->findModel($zu_id);
         $item_ids = Yii::$app->request->post('item_id');
         foreach ($item_ids as $key => $one_item) {
             //父类直接删除
             if (count(explode('/', $one_item)) == 3) {
                 unset($item_ids[$key]);
             }
         }
         $children = $auth->getChildren($zu_id);
         foreach ($children as $son) {
             if (!in_array($son->name, $item_ids)) {
                 $auth->removeChild($zu_model, $son);
             }
         }
         foreach ($item_ids as $item_id) {
             $item_obj = $this->findModel($item_id);
             if (!$auth->hasChild($zu_model, $item_obj)) {
                 $auth->addChild($zu_model, $item_obj);
             }
         }
         return json_encode(['status' => 1]);
     }
     $zu_id = Yii::$app->request->get('id');
     $zu_model = $this->findModel($zu_id);
     //所有的操作
     $list = AuthItem::find()->where(['type' => '2'])->all();
     //组装新数组
     $new_list = array();
     $key_arr = array();
     $is_have_arr = [];
     foreach ($list as $row) {
         $is_have_arr[$row->name] = $auth->hasChild($zu_model, $row);
         $key_arr[$row->name] = $row;
     }
     $child_arr = [];
     foreach ($list as $row) {
         $child = $auth->getChildren($row->name);
         if ($child) {
             foreach ($child as $key => $value) {
                 $child_arr[$row->name][] = $key_arr[$key];
             }
             $new_list[] = $row;
         }
     }
     return $this->render('auth', array('list' => $new_list, 'item_zu_id' => $zu_id, 'is_have_arr' => $is_have_arr, 'child_arr' => $child_arr));
 }
示例#9
0
文件: _form.php 项目: vchandwani/yii
/* @var $this yii\web\View */
/* @var $model backend\models\AuthItemChild */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="auth-item-child-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'parent')->widget(Select2::classname(), ['data' => ArrayHelper::map(AuthItem::find()->where(['and', "type=1"])->all(), 'name', 'name'), 'language' => 'en', 'options' => ['placeholder' => 'Please Select']]);
?>
    
    <?php 
echo $form->field($model, 'child')->widget(Select2::classname(), ['data' => ArrayHelper::map(AuthItem::find()->where(['and', "type=2"])->all(), 'name', 'name'), 'language' => 'en', 'options' => ['placeholder' => 'Please Select']]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
示例#10
0
<?php

/**
 * Created by PhpStorm.
 * User: vrigzlinuxmint13
 * Date: 9/6/15
 * Time: 4:06 PM
 */
use backend\models\AuthItem;
use backend\models\User;
// Find all users first, else it will stop the script
if (!empty($getAllUsers = User::find()->all())) {
    // Find all auth items first, else it will stop the script
    if (!empty($getAllAuthItems = AuthItem::find()->all())) {
        foreach ($getAllAuthItems as $authItems) {
            $allAuthItems[] = $authItems->name;
        }
    } else {
        exit("No 'auth item' data in '" . AuthItem::tableName() . "' table." . PHP_EOL);
    }
    // Check if 'admin' exists, else stop the script
    if (in_array('admin', $allAuthItems)) {
        $getAdminOnly = array_search('admin', $allAuthItems);
    } else {
        exit("Create an 'admin' first in " . AuthItem::tableName() . " table" . PHP_EOL);
    }
    // Random created/updated dates
    $created = $faker->dateTimeBetween('-7 days', 'now')->format('Y-m-d H:i:s');
    foreach ($getAllUsers as $user) {
        // Well, search me first before anything else :D
        if ($user->username === 'vrigzalejo') {
示例#11
0
文件: _form.php 项目: nym3ny/westwolf
echo $form->field($model, 'password_reset_token')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'status')->textInput();
?>

    <?php 
echo $form->field($model, 'created_at')->textInput();
?>

    <?php 
echo $form->field($model, 'updated_at')->textInput();
?>

    <?php 
echo $form->field($model, 'auth_assignment')->dropDownList(ArrayHelper::map(\backend\models\AuthItem::find()->all(), 'name', 'name'), ['prompt' => 'Select Role']);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
示例#12
0
<?php

/**
 * Created by PhpStorm.
 * User: vrigzlinuxmint13
 * Date: 9/6/15
 * Time: 1:58 PM
 */
use backend\models\AuthItem;
// Search for 'admin' name in auth_item table first
if (!empty($authItem = AuthItem::find()->where(['name' => 'admin'])->one())) {
    // Find all auth_items except 'admin'
    foreach ($allAuthItems = AuthItem::find()->all() as $aItem) {
        if ($aItem->name !== 'admin') {
            $authItemChildData[] = ['parent' => $authItem->name, 'child' => $aItem->name];
        }
    }
    // Db seed auth_item_child according to parent-child relationship
    if ($index < count($allAuthItems) - 1) {
        return $authItemChildData[$index];
    } else {
        exit("Please set '" . preg_replace('/\\.php$/', '', basename(__FILE__)) . "' --count from 1 up to " . count($authItemChildData) . PHP_EOL);
    }
} else {
    exit("No 'admin' data in '" . AuthItem::tableName() . "' table." . PHP_EOL);
}
示例#13
0
/* @var $this yii\web\View */
/* @var $model backend\models\AuthItemChild */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="auth-item-child-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'parent')->dropDownList(ArrayHelper::map(AuthItem::find()->all(), 'name', 'name'), ['prompt' => 'Select parent permission']);
?>

    <?php 
echo $form->field($model, 'child')->dropDownList(ArrayHelper::map(AuthItem::find()->all(), 'name', 'name'), ['prompt' => 'Select child permission']);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>