예제 #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
 /**
  * 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
 /**
  * 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
 /**
  * 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
 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.');
     }
 }