Example #1
0
 /**
  * function check user role is super admin
  * @param type $username
  * @return boolean
  */
 public function isSuperAdmin($username)
 {
     if (BUser::findOne(['username' => $username, 'role' => self::getAuthName('ROLE_SYSADMIN')])) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'index' page.
  * @return mixed
  */
 public function actionCreate()
 {
     /** @var User $user */
     $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'create']);
     $this->performAjaxValidation($user);
     if ($user->load(\Yii::$app->request->post()) && $user->create()) {
         $this->updateUser($user->id, BUser::getAuthName('ROLE_MEMBER'));
         \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been created'));
         return $this->redirect(['index']);
     }
     return $this->render('create', ['user' => $user]);
 }
Example #3
0
 public function behaviors()
 {
     return ['access' => ['class' => AccessControl::className(), 'rules' => [['allow' => true, 'roles' => ['@'], 'matchCallback' => function () {
         return BUser::isSuperAdmin(\Yii::$app->user->identity->username);
     }]]]];
 }