Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(Site): Add page Site/{Logs,Rules}
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Aug 17, 2019
1 parent ccde9c0 commit 65cea9e
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 203 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
- **template:** Add git commit hash in `CHANGELOG.md` (76bc527)

### Feat
- **Auth:** Sep Auth part from Site to new components (f36884e)
- **Auth:** Add Auth By passkey support for special route (aff1f87)
- **Auth:** Use JWT to set cookies content (bf897c6)
- **Auth:** Sep Auth part from Site to new components (f36884e)
- **Auth/Login:** Add full Advanced Options support (6009dc8)
- **Secret:** Check session and user_id match or not in jwt payload (358ba5d)
- **Secret:** Protect jwt key for env('APP_SECRET_KEY') (dfa67da)
- **Sessions:** record user access information at Auth->onRequestAfter() (e2a22a7)
- **Sessions/List:** Use SessionsListForm to show user sessions (9ecfb97)
- **Torrent/Download:** Add user download pos check (db6d5ff)
- **Torrent/Search:** Use MySQL fulltext search. (354c07b)
- **ban_ips:** Store banned ip in components/Site (01084c9)
- **torrents/tags:** Store torrent tags in TABLE `torrents` (4d573e2)

Expand Down
30 changes: 30 additions & 0 deletions apps/controllers/SiteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 8/17/2019
* Time: 2019
*/

namespace apps\controllers;


use apps\models\form\Site;
use Rid\Http\Controller;

class SiteController extends Controller
{
public function actionRules()
{
return $this->render('site/rules');
}

public function actionLogs()
{
$logs = new Site\Logs();
if (!$logs->validate()) {
return $this->render('action/action_fail',['msg'=>$logs->getError()]);
}
return $this->render('site/logs',['logs'=>$logs]);
}
}
1 change: 0 additions & 1 deletion apps/controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function actionSearch()
{
// TODO add URI level Cache
$search = new Torrents\SearchForm();
var_dump(app()->request->get());
$search->setInput(app()->request->get());
$success = $search->validate();
if (!$success) {
Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/News/SearchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace apps\models\form\News;


use Rid\Validators\Pager;
use Rid\Validators\Pagination;

class SearchForm extends Pager
class SearchForm extends Pagination
{

public $query;
Expand Down
85 changes: 85 additions & 0 deletions apps/models/form/Site/Logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 8/17/2019
* Time: 2019
*/

namespace apps\models\form\Site;


use Rid\Validators\Pagination;

class Logs extends Pagination
{

protected $_levels;

public static $MAX_LIMIT = 100;

protected $_autoload = true;
protected $_autoload_from = ['get'];

public static function defaultData(): array
{
return [
'page' => static::getDefaultPage(),
'limit' => static::getDefaultLimit(),
'level' => 'all'
];
}

public static function inputRules(): array
{
$level_list = ['all', 'normal'];
if (app()->auth->getCurUser()->isPrivilege('see_site_log_mod')) $level_list[] = 'mod';
if (app()->auth->getCurUser()->isPrivilege('see_site_log_leader')) $level_list[] = 'leader';

return [
'page' => 'Integer', 'limit' => 'Integer',
'level' => [
['RequiredWith', ['item' => 'query']],
['inList', ['list' => $level_list]]
]
];
}

private function getLevels() {
if (!is_null($this->_levels)) return $this->_levels;

$input_level = $this->getInput('level');
if ($input_level == 'all') {
$levels = ['normal'];
if (app()->auth->getCurUser()->isPrivilege('see_site_log_mod')) $levels[] = 'mod';
if (app()->auth->getCurUser()->isPrivilege('see_site_log_leader')) $levels[] = 'leader';
} else {
$levels = [$input_level];
}

$this->_levels = $levels;
return $this->_levels;
}

protected function getRemoteTotal(): int
{
$search = $this->getInput('query');
return app()->pdo->createCommand([
['SELECT COUNT(*) FROM `site_log` WHERE 1=1 '],
['AND `level` IN (:l) ', 'params' => ['l' => $this->getLevels()]],
['AND `msg` LIKE :search ', 'if' => strlen($search), 'params' => ['search' => "%$search%"]]
])->queryScalar();
}

protected function getRemoteData(): array
{
$search = $this->getInput('query');
return app()->pdo->createCommand([
['SELECT * FROM `site_log` WHERE 1=1 '],
['AND `level` IN (:l) ', 'params' => ['l' => $this->getLevels()]],
['AND `msg` LIKE :search ', 'if' => strlen($search), 'params' => ['search' => "%$search%"]],
['ORDER BY create_at DESC '],
['LIMIT :offset, :rows', 'params' => ['offset' => $this->offset, 'rows' => $this->limit]]
])->queryAll();
}
}
4 changes: 2 additions & 2 deletions apps/models/form/Subtitles/SearchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

use apps\libraries\Constant;

use Rid\Validators\Pager;
use Rid\Validators\Pagination;

class SearchForm extends Pager
class SearchForm extends Pagination
{

public $search;
Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/Torrent/CommentsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
namespace apps\models\form\Torrent;


use Rid\Validators\PagerTrait;
use Rid\Validators\PaginationTrait;

class CommentsForm extends DetailsForm
{
use PagerTrait;
use PaginationTrait;

public static $DEFAULT_LIMIT = 20;
public static $MAX_LIMIT = 50;
Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/Torrent/SnatchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace apps\models\form\Torrent;

use Rid\Validators\PagerTrait;
use Rid\Validators\PaginationTrait;

class SnatchForm extends DetailsForm
{
use PagerTrait;
use PaginationTrait;

public static $MAX_LIMIT = 100;

Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/Torrents/SearchForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace apps\models\form\Torrents;

use Rid\Validators\Pager;
use Rid\Validators\Pagination;

class SearchForm extends Pager
class SearchForm extends Pagination
{

public static $MAX_LIMIT = 100;
Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/Torrents/TagsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace apps\models\form\Torrents;


use Rid\Validators\Pager;
use Rid\Validators\Pagination;

class TagsForm extends Pager
class TagsForm extends Pagination
{
public $search;

Expand Down
4 changes: 2 additions & 2 deletions apps/models/form/User/SessionsListForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace apps\models\form\User;


use Rid\Validators\Pager;
use Rid\Validators\Pagination;

class SessionsListForm extends Pager
class SessionsListForm extends Pagination
{
public $uid;
public $expired = [-1, 0]; // Default not show expired session
Expand Down
2 changes: 1 addition & 1 deletion apps/views/layout/nav_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<li><a href="/site/topten"><?= __('nav_topten') ?></a></li> <!-- TODO -->
<li class="divider"></li>
<li><a href="/site/stats"><?= __('nav_stats') ?></a></li> <!-- TODO -->
<li><a href="/site/log"><?= __('nav_log') ?></a></li> <!-- TODO -->
<li><a href="/site/logs"><?= __('nav_log') ?></a></li>
</ul>
</li>
</ul> <!-- END .navbar-nav -->
Expand Down
72 changes: 72 additions & 0 deletions apps/views/site/logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 8/17/2019
* Time: 2019
*
* @var League\Plates\Template\Template $this
* @var \apps\models\form\Site\Logs $logs
*/
?>

<?= $this->layout('layout/base') ?>

<?php $this->start('title') ?>Site Logs<?php $this->end(); ?>

<?php $this->start('container') ?>
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading">Search Daily Log</div>
<div class="panel-body">
<form class="form form-inline" method="get">
<div class="form-group">
<label for="query"></label>
<input id="query" class="form-control col-md-6" type="text" name="query" value="<?= $this->e(app()->request->get('query')) ?>" style="width: 500px">
</div>
<div class="form-group">
<label for="level"> In </label>
<select id="level" class="form-control" name="level">
<option value="all"<?= app()->request->get('level') == 'all' ? ' selected' : '' ?>>all</option>
<option value="normal"<?= app()->request->get('level') == 'normal' ? ' selected' : '' ?>>normal</option>
<?php if (app()->auth->getCurUser()->isPrivilege('see_site_log_mod')): ?>
<option value="mod"<?= app()->request->get('level') == 'mod' ? ' selected' : '' ?>>mod</option>
<?php endif; ?>
<?php if (app()->auth->getCurUser()->isPrivilege('see_site_log_leader')): ?>
<option value="leader"<?= app()->request->get('level') == 'leader' ? ' selected' : '' ?>>leader</option>
<?php endif; ?>
</select>
</div>
<button type="submit" class="btn btn-primary">Search</button>
</form>
</div>
</div>
<div class="panel">
<div class="panel-heading">Other rules</div>
<div class="panel-body">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Time</th>
<th style="width: 99%;">Event</th>
</tr>
</thead>
<tbody>
<?php foreach ($logs->getPagerData() as $log) : ?>
<tr>
<td><span class="nowrap"><?= $log['create_at'] ?></span></td>
<td><?= $this->e($log['msg']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="text-center">
<ul class="pager pager-unset-margin" data-ride="remote_pager" data-rec-total="<?= $logs->getTotal() ?>" data-rec-per-page="<?= $logs->getLimit() ?>"></ul>
</div>
</div>
</div>
</div>
</div>
<?php $this->end(); ?>

37 changes: 37 additions & 0 deletions apps/views/site/rules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 8/17/2019
* Time: 2019
*/
?>

<?= $this->layout('layout/base') ?>

<?php $this->start('title') ?>Subtitle<?php $this->end(); ?>

<?php $this->start('container') ?>
<div class="row">
<div class="col-md-12">
<div class="panel-group">
<div class="panel">
<div class="panel-heading">General rules - Breaking these rules can and will get you banned!</div>
<div class="panel-body">
<ul>
<li>Do not do things we forbid.</li>
<li>Do not spam.</li>
<li>Cherish your user account. Inactive accounts would be deleted based on the following </li>
</ul>
</div>
</div>
<div class="panel">
<div class="panel-heading">Other rules</div>
<div class="panel-body">
...
</div>
</div>
</div>
</div>
</div>
<?php $this->end(); ?>
Loading

0 comments on commit 65cea9e

Please sign in to comment.