Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $scope = 'active')
 {
     $query = YBoardBan::find();
     if ($scope == 'active') {
         $query = $query->activeScope();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'expires' => $this->expires, 'banned_by' => $this->banned_by]);
     $query->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 public function updateOnlineStatus($action)
 {
     //Timed JS function
     //fetch current user list and add update statistics
     //js to Update it for a time
     session_start();
     Yii::$app->view->registerJs(" \n            function updateOnlineUsers() {\n                \$.get('" . Yii::$app->urlManager->createUrl([$this->id . '/member/update-online-status', 'id' => Yii::$app->session->id, 'uid' => Yii::$app->user->id]) . "')\n                .done(function(data){\n                    data = \$.parseJSON(data);\n                    console.log(data);\n                    \$('#online-record').html(data.message);\n                }); \n            }\n            \n            //call function to immediately update online users\n            updateOnlineUsers();\n            setInterval(updateOnlineUsers," . $this->onlineLimit * 1000 . ");\n        ");
     // register visit by guest or user
     /*$session = YBoardSession::findOne(Yii::$app->session->id);
       if($session == null) {
           $session = new YBoardSession;
           $session->setAttributes([
               'id'=>Yii::$app->session->id,
               'user_id'=>Yii::$app->user->isGuest ? NULL : Yii::$app->user->id,
               'last_visit'=>time(),
           ]); 
       }               
       $session->save() ;  */
     // register last visit by member
     if (!Yii::$app->user->isGuest) {
         $model = YBoardMember::findOne(Yii::$app->user->id);
         if ($model !== null) {
             $model->last_visit = date('Y-m-d H:i:s');
             $model->save();
             //banned user are not allowed to access anything. So they have to be guests
             if ($action->id != 'banned' && $action->id != 'error') {
                 Event::on(self::className(), self::EVENT_AFTER_ACTION, function ($event) {
                     //if banned redirect to banned
                     $ban = YBoardBan::find()->where(['user_id' => Yii::$app->user->id])->orWhere(['ip' => Yii::$app->request->userIP])->andWhere('expires>' . time())->one();
                     if ($ban != null) {
                         return Yii::$app->response->redirect([$this->id . '/forum/banned', 'id' => $ban->id])->send();
                     }
                 });
             }
         } else {
             //redirect to associate member with forum account
             //no user can access forum logged in without member account
             if ($action->id != 'banned' && $action->id != 'error' && $action->id != 'associate' && $action->controller->id != 'member') {
                 Event::on(self::className(), self::EVENT_AFTER_ACTION, function ($event) {
                     return Yii::$app->response->redirect([$this->id . '/member/associate', 'id' => Yii::$app->user->id])->send();
                 });
             }
         }
     }
 }
Ejemplo n.º 3
0
 public function isBanned()
 {
     return YBoardBan::find()->where(['user_id' => $this->id])->exists();
 }
 /** Ban Specific User 
  */
 public function actionBanUser($id)
 {
     if (!Yii::$app->user->can('app.forum.moderator.ban-user')) {
         throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
     }
     if (!Yii::$app->request->isAjax) {
         Yii::$app->end();
     }
     $json = [];
     $user = YBoardBan::find()->where(['user_id' => $id])->one();
     if ($user == null) {
         $user = new YBoardBan();
     }
     $attribs = $_POST;
     $attribs['expires'] = strtotime($attribs['expires']);
     $attribs['user_id'] = $id;
     $user->attributes = $attribs;
     if ($user->save()) {
         $json['success'] = 'yes';
     } else {
         $json['success'] = 'no';
         $json['message'] = YBoard::t('yboard', 'Could Not Ban User!');
     }
     echo json_encode($json);
     Yii::$app->end();
 }