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 beforeDelete()
 {
     if (parent::beforeDelete()) {
         //delete: Messages(to/from), Ban History, UpVotes, LogTopic
         YBoardMessage::deleteAll(['or', 'sendfrom' => $this->id, 'sendto' => $this->id]);
         // Post(Polls and Votes)
         YBoardVote::deleteAll(['user_id' => $this->id]);
         YBoardUpvoted::deleteAll(['member_id' => $this->id]);
         YBoardPoll::deleteAll(['user_id' => $this->id]);
         YBoardPost::deleteAll(['user_id' => $this->id]);
         //log topic
         YBoardLogTopic::deleteAll(['member_id' => $this->id]);
         //ban
         YBoardBan::deleteAll(['user_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
 /** Lift Ban
  */
 public function actionBanLift($id)
 {
     if (!Yii::$app->user->can('app.forum.moderator.ban-lift')) {
         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 = [];
     $ban = YBoardBan::findOne($id);
     $ban->setAttribute('expires', time() - 60);
     //expired one minute ago
     if ($ban != null && $ban->save()) {
         $json['success'] = 'yes';
     } else {
         $json['success'] = 'no';
         $json['error'] = YBoard::t('yboard', 'Could Not Lift the Ban!');
     }
     echo json_encode($json);
     Yii::$app->end();
 }
Ejemplo n.º 5
0
 /**
  * Displays a single YBoardBan model.
  * @param integer $id
  * @return mixed
  */
 public function actionBanned($id)
 {
     $model = YBoardBan::findOne($id);
     $user = YBoardMember::findOne($model->user_id);
     $isIP = true;
     if ($user !== null) {
         $isIP = false;
     }
     if ($model == null) {
         throw new NotFoundHttpException(YBoard::t('yboard', 'The requested Banned User does not exist.'));
     }
     $settings = YBoardSetting::find()->where(['key' => 'email'])->one();
     return $this->render('banned', ['model' => $model, 'member' => $user, 'isIp' => $isIP, 'email' => $settings == null ? YBoard::t('board', 'no email') : $settings->value]);
 }