/**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     $profile = $user->profile;
     UserKey::deleteAll(['user_id' => $user->id]);
     UserAuth::deleteAll(['user_id' => $user->id]);
     $profile->delete();
     $user->delete();
     return $this->redirect(['index']);
 }
示例#2
0
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     $profile = $user->profile;
     UserKey::deleteAll(['user_id' => $user->id]);
     UserAuth::deleteAll(['user_id' => $user->id]);
     $profile->delete();
     $user->delete();
     //删除授权
     Yii::$app->authManager->revoke(Yii::$app->authManager->getRole($user->role), $user->id);
     return $this->redirect(['index']);
 }
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     // If user has admin role, check if the one
     if ($user->role->id === Role::ROLE_ADMIN && User::find()->where(['role_id' => Role::ROLE_ADMIN])->count() < 2) {
         Yii::$app->session->setFlash('danger', Yii::t('app', "You need to create another user with 'Admin' role in order to delete your account."));
     } else {
         $profile = $user->profile;
         UserKey::deleteAll(['user_id' => $user->id]);
         UserAuth::deleteAll(['user_id' => $user->id]);
         FormUser::deleteAll(["user_id" => $user->id]);
         $profile->delete();
         $user->delete();
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'The user has been successfully deleted.'));
     }
     return $this->redirect(['index']);
 }