public function actionResetPassword($barcodeId = NULL)
 {
     /*         * *************  Step2  * ************* */
     if (isset($barcodeId)) {
         $errorMsg = '';
         $modelBarcode = UserBarcode::model()->findByPk($barcodeId);
         $model = User::model()->getUserAndBarcode($barcodeId);
         $model->scenario = 'requiredCaptcha';
         if (isset($_POST['UserBarcode']['barcode'])) {
             if ($_POST['UserBarcode']['barcode'] === $modelBarcode->barcode && Yii::app()->extraFunctions->checkLiveTime($modelBarcode->end_time)) {
                 $this->render('changePassword', array('model' => $model, 'type' => 1));
                 return;
             } else {
                 $errorMsg = 'Your barcode is invalid or expired.';
             }
         } elseif (isset($_POST['User'])) {
             $_POST['User']['salt'] = Yii::app()->extraFunctions->randomString(32);
             $_POST['User']['password'] = md5(md5($_POST['User']['salt']) . $_POST['User']['password']);
             $model->attributes = $_POST['User'];
             $model->update();
             $modelBarcode->end_time = 0;
             $modelBarcode->status = 1;
             $modelBarcode->update();
             Yii::app()->user->setFlash('success', Yii::t('backend', 'Changing password successful.'));
             $this->redirect(array('site/login'));
         }
         /*             * *************End Step 3************ */
         $this->render('changePassword', array('type' => 0, 'errorMsg' => $errorMsg));
     } else {
         $this->redirect(array('site/login'));
     }
 }
 public function actionDelete()
 {
     if (isset($_POST['trash'])) {
         $model = $this->loadModel($_POST['id']);
         if (!Yii::app()->user->checkAccess('super user')) {
             /////////////////
             if (User::model()->getRoleUser($_POST['id']) == 'super user') {
                 $this->redirect(array('/' . backend . '/default/ErrorAuth'));
             }
         }
         //////////////
         if ($_POST['trash'] == 1) {
             $model->status = 2;
             if ($model->save(true, array('status'))) {
                 Yii::app()->user->setFlash('success', Yii::t('user', 'User moved to trash.'));
             } else {
                 Yii::app()->user->setFlash('error', Yii::t('user', 'User cannot move to trash. Please try it later.'));
             }
             $this->redirect(array('/' . backend . '/user/admin'));
         } else {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 if (UserProfile::model()->exists('userid=' . $model->id)) {
                     UserProfile::model()->findByPk($model->id)->delete();
                 }
                 if (UserBarcode::model()->exists('userid=' . $model->id)) {
                     UserBarcode::model()->deleteAll('userid=' . $model->id);
                 }
                 Post::model()->updateAll(array('created_by' => ''), 'created_by=' . $model->id);
                 Post::model()->updateAll(array('modified_by' => ''), 'modified_by=' . $model->id);
                 AuthAssignment::model()->deleteAll('userid=:iduser', array(':iduser' => $model->id));
                 if ($model->delete()) {
                     $transaction->commit();
                     Yii::app()->user->setFlash('success', Yii::t('user', 'User was deleted from system.'));
                 }
             } catch (Exception $e) {
                 Yii::app()->user->setFlash('error', Yii::t('user', 'User cannot delete. Please try it later.'));
                 $transaction->rollback();
             }
             $this->redirect(array('/' . backend . '/user/trash'));
         }
     }
 }