/**
  * Retrieves a list of models based on the current search/filter conditions.
  *
  * Typical usecase:
  * - Initialize the model fields with values from filter form.
  * - Execute this method to get CActiveDataProvider instance which will filter
  * models according to data in model fields.
  * - Pass data provider to CGridView, CListView or any similar widget.
  *
  * @return CActiveDataProvider the data provider that can return the models
  * based on the search/filter conditions.
  */
 public function search()
 {
     // @todo Please modify the following code to remove attributes that should not be searched.
     $criteria = new CDbCriteria();
     $criteria->compare('id', $this->id, true);
     $criteria->compare('user_id', $this->user_id, true);
     $criteria->compare('name', $this->name, true);
     $criteria->compare('date_create', $this->date_create, true);
     $criteria->compare('ignored', $this->ignored, true);
     if (!WebUser::isAdmin()) {
         $criteria->compare('user_id', WebUser::Id());
     }
     $criteria->order = 'user_id, ignored DESC, name';
     return new CActiveDataProvider($this, array('criteria' => $criteria));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if (!WebUser::isAdmin()) {
         if (WebUser::Id() != $id) {
             throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
         }
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Users'])) {
         $model->attributes = $_POST['Users'];
         $model->password = CPasswordHelper::hashPassword(trim($model->password));
         if ($model->save()) {
             $this->setFlashSuccess('User password for <strong>' . $model->username . '</strong> successfully changed');
             $this->redirect(array('admin'));
         }
     }
     $this->render('update', array('model' => $model));
 }
 private function initMenu()
 {
     $this->main_menu = array(array('label' => 'Home', 'url' => array('/site/index')), array('label' => 'Search', 'url' => array('/search/index')), array('label' => 'Lists', 'url' => array('/listing/index'), 'visible' => !WebUser::isGuest()), array('label' => '|', 'url' => '#', 'visible' => !WebUser::isGuest()), array('label' => 'Users', 'url' => array('/users/admin'), 'visible' => WebUser::isAdmin()), array('label' => 'Profile', 'url' => array('/users/update', 'id' => WebUser::Id()), 'visible' => !WebUser::isGuest()), array('label' => '|', 'url' => '#', 'visible' => !WebUser::isGuest()), array('label' => 'Login', 'url' => array('/site/login'), 'visible' => WebUser::isGuest()), array('label' => 'Register', 'url' => array('/site/register'), 'visible' => WebUser::isGuest()), array('label' => 'Logout (' . Yii::app()->user->name . ')', 'url' => array('/site/logout'), 'visible' => !WebUser::isGuest()));
 }
Esempio n. 4
0
 /**
  * Indique si l'utilisateur est un administrateur du site ou pas.
  * Par défaut, il faut avoir l'attribut $superuser à true pour cela
  * @return bool
  * @internal Ne pas oublier de surcharger cette méthode dans myWebUser si on utilise un contrôle d'accès
  *           => on marque la méthode deprecated dans cette classe pour faire un rappel visuel dans PHPStorm
  * @deprecated
  */
 public function isAdmin()
 {
     if (self::$isAdmin !== null) {
         return self::$isAdmin;
     }
     $user = $this->getUser();
     if (!$user) {
         self::$isAdmin = false;
     } else {
         self::$isAdmin = $user->superuser === true;
     }
     return self::$isAdmin;
 }
Esempio n. 5
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $this->layout = '//layout/blankLayout';
     $model = new LoginForm();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate() && $model->login()) {
             //$this->redirect(Yii::app()->user->returnUrl);
             if (Yii::app()->user->isLogin) {
                 $userid = Yii::app()->user->idUser;
                 $timestamp = date('Y-m-d H:i:s');
                 User::model()->updateByPk($userid, array('TERAKHIR_LOGIN' => $timestamp));
                 if (WebUser::isAdmin()) {
                     $this->redirect(array('/admin'));
                 } else {
                     $this->redirect(array('/site'));
                 }
             }
         }
     }
     // display the login form
     $this->render('login', array('model' => $model));
 }
Esempio n. 6
0
<?php

if (WebUser::isAdmin()) {
    $this->breadcrumbs = array_merge(array('<i class="fa fa-home"></i> Home' => array('/'), 'Administrator' => array('/admin')), $this->breadcrumbs);
} else {
    $this->breadcrumbs = array_merge(array('<i class="fa fa-home"></i> Home' => array('/site')), $this->breadcrumbs);
}
$this->widget('zii.widgets.CBreadcrumbs', array('links' => $this->breadcrumbs, 'homeLink' => false, 'encodeLabel' => false, 'tagName' => 'ul', 'separator' => '', 'activeLinkTemplate' => '<li><a href="{url}">{label}</a><i class="fa fa-angle-right"></i></li>', 'inactiveLinkTemplate' => '<li>{label}</li>', 'htmlOptions' => array('class' => 'page-breadcrumb breadcrumb')));