/**
  * 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
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (Yii::$app->user->can('userUpdate')) {
         //The permission name
         //The actions...
         $model = $this->findModel($id);
         $role = new AuthItem();
         $auth = Yii::$app->authManager;
         $currentRole = $auth->getRolesByUser($model->getId());
         $role->name = key($currentRole);
         $password = $model->password;
         $model->password = '';
         if ($model->load(Yii::$app->request->post())) {
             if ($model->password == '') {
                 $model->password = $password;
             }
             if ($model->save()) {
                 $role->load(Yii::$app->request->post());
                 $newRole = $auth->getRole($role->name);
                 if ($newRole != $currentRole) {
                     $auth->revokeAll($model->getId());
                     $auth->assign($newRole, $model->getId());
                 }
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('update', ['model' => $model, 'role' => $role]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }