Example #1
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = BackendUser::findByUsername($this->username);
     }
     return $this->_user;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BackendUser::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(['is_admin' => $this->is_admin, 'id' => $this->id]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password]);
     return $dataProvider;
 }
Example #3
0
$this->title = 'List';
$this->params['breadcrumbs'][] = ['label' => 'Messages', 'url' => ['list']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="message-view">

    <h1><?php 
Html::encode($this->title);
?>
</h1>
	<ul>

<?php 
echo $this->render('_form', ['model' => $model]);
?>

    <?php 
echo '<i>p.s. Refresh the page to see new messages.</i><br><br>';
foreach ($messages as $message) {
    $c = "\"message\"";
    if (Yii::$app->user->identity->id == $message->creator_id) {
        $c = "\"message my_message\"";
    }
    $name = HtmlPurifier::process(BackendUser::findOne($message->creator_id)->username);
    $stuffs = HtmlPurifier::process(Parsedown::instance()->text($message->content));
    echo "<li class=" . $c . "><h5 class=\"username\">" . $name . " says: </h5><div class=\"content\">" . $stuffs . "</div><h6 class=\"timestamp\">posted at: " . $message->timestamp . "</h6></li>";
}
?>
</ul>
</div>
 /**
  * Finds the BackendUser model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BackendUser the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BackendUser::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
 public function beforeSave($insert)
 {
     BackendUser::find()->where('id != -1')->count() == 0 ? $this->is_admin = true : ($this->is_admin = false);
     $this->password = Yii::$app->getSecurity()->generatePasswordHash($this->password);
     return parent::beforeSave($insert);
 }