コード例 #1
0
 public function actionInit()
 {
     $rbac = Yii::$app->authManager;
     //role untuk guest
     $guest = $rbac->createRole('guest');
     $guest->description = 'Nobody';
     $rbac->add($guest);
     //role untuk user
     $user = $rbac->createRole('user');
     $user->description = 'untuk user yang login';
     $rbac->add($user);
     //role untuk manager
     $manager = $rbac->createRole('manager');
     $manager->description = 'untuk manager yang login';
     $rbac->add($manager);
     //role untuk admin
     $admin = $rbac->createRole('admin');
     $admin->description = 'untuk admin yang login';
     $rbac->add($admin);
     //hirarki role
     $rbac->addChild($admin, $manager);
     $rbac->addChild($manager, $user);
     $rbac->addChild($user, $guest);
     //assign ke user tabel yg ada di db
     $rbac->assign($user, UserRecord::findOne(['username' => 'andhika'])->user_id);
     $rbac->assign($manager, UserRecord::findOne(['username' => 'manager'])->user_id);
     $rbac->assign($admin, UserRecord::findOne(['username' => 'admin'])->user_id);
 }
コード例 #2
0
ファイル: LoginForm.php プロジェクト: soanni/yii2news
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         //$this->_user = User::findByUsername($this->username);
         $this->_user = UserRecord::findByUsername($this->username);
     }
     return $this->_user;
 }
コード例 #3
0
 public function createUrl($manager, $route, $params)
 {
     if ($route !== 'user/view' || !array_key_exists('id', $params)) {
         return false;
     }
     $user = UserRecord::findOne($params['id']);
     if (!$user) {
         return false;
     } else {
         return "{$user->username}";
     }
 }
コード例 #4
0
ファイル: UserSearch.php プロジェクト: billcccheng/Yii2-Basic
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserRecord::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', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password]);
     return $dataProvider;
 }
コード例 #5
0
ファイル: UserSearch.php プロジェクト: andhikayuana/latyii2
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserRecord::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username]);
     return $dataProvider;
 }
コード例 #6
0
ファイル: LoginForm.php プロジェクト: billcccheng/Yii2-Basic
 private function fetchUser($username)
 {
     return UserRecord::findOne(compact('username'));
 }
コード例 #7
0
 /**
  * Finds the UserRecord model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserRecord::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }