/**
  * Creates a new AuthItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AuthItem();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->name]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new AuthItem model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AuthItem();
     $searchModel = new AuthItemSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->name]);
     } else {
         return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     }
 }
Exemplo n.º 3
0
 public function testAssignRole()
 {
     $user = $this->tester->grabFixture('user', 'user-2');
     $role = new AuthItem(['type' => \yii\rbac\Item::TYPE_ROLE, 'name' => 'test', 'description' => 'test_description']);
     expect_that($role->save());
     $user->role = $role->name;
     expect_that($user->save());
     $user = User::findByEmail($user->email);
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole($user->role), $user->id);
     expect_that($user->roles->name === $role->name);
     expect($user->role)->equals($role->name);
     expect(key($auth->getRolesByUser($user->id)))->equals($role->name);
     $role->delete();
 }