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

Commit

Permalink
style(cs-fixer): Update Composer config and php-cs-fixer whole project
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jan 13, 2020
1 parent b29c2f6 commit e734812
Show file tree
Hide file tree
Showing 134 changed files with 715 additions and 516 deletions.
41 changes: 30 additions & 11 deletions application/Components/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ public function getGrant(): string
protected function loadCurUser($grant = 'cookies')
{
$user_id = false;
if ($grant == 'cookies') $user_id = $this->loadCurUserIdFromCookies();
elseif ($grant == 'passkey') $user_id = $this->loadCurUserIdFromPasskey();
if ($grant == 'cookies') {
$user_id = $this->loadCurUserIdFromCookies();
} elseif ($grant == 'passkey') {
$user_id = $this->loadCurUserIdFromPasskey();
}

if ($user_id !== false && is_int($user_id) && $user_id > 0) {
$user_id = intval($user_id);
$curuser = app()->site->getUser($user_id);
if ($curuser->getStatus() !== UserStatus::DISABLED) // user status shouldn't be disabled
if ($curuser->getStatus() !== UserStatus::DISABLED) { // user status shouldn't be disabled
return $curuser;
}
}

return false;
Expand All @@ -82,16 +86,24 @@ protected function loadCurUser($grant = 'cookies')
protected function loadCurUserIdFromCookies()
{
$user_session = app()->request->cookie(Constant::cookie_name);
if (is_null($user_session)) return false; // quick return when cookies is not exist
if (is_null($user_session)) {
return false;
} // quick return when cookies is not exist

$payload = JWTHelper::decode($user_session);
if ($payload === false) return false;
if (!isset($payload['jti']) || !isset($payload['aud'])) return false;
if ($payload === false) {
return false;
}
if (!isset($payload['jti']) || !isset($payload['aud'])) {
return false;
}

// Check if user lock access ip ?
if (isset($payload['ip'])) {
$now_ip_crc = sprintf('%08x', crc32(app()->request->getClientIp()));
if (strcasecmp($payload['ip'], $now_ip_crc) !== 0) return false;
if (strcasecmp($payload['ip'], $now_ip_crc) !== 0) {
return false;
}
}

// Verity $jti is force expired or not by checking mapUserSessionToId
Expand All @@ -101,14 +113,19 @@ protected function loadCurUserIdFromCookies()
'sid' => $payload['jti']
])->queryScalar();
app()->redis->zAdd(Constant::mapUserSessionToId, $uid ?: 0, $payload['jti']); // Store 0 if session -> uid is invalid
if ($uid === false) return false; // this session is not exist or marked as expired
} elseif ($expired_check != $payload['aud']) return false; // may return (double) 0 , which means already make invalid ; or it check if user obtain this session (may Overdesign)
if ($uid === false) {
return false;
} // this session is not exist or marked as expired
} elseif ($expired_check != $payload['aud']) {
return false;
} // may return (double) 0 , which means already make invalid ; or it check if user obtain this session (may Overdesign)

$this->cur_user_jit = $payload['jti'];

// Check if user want secure access but his environment is not secure
if (!app()->request->isSecure() && // if User requests is not secure , and
(config('security.ssl_login') > 1 || // if Our site FORCE enabled ssl feature
(
config('security.ssl_login') > 1 || // if Our site FORCE enabled ssl feature
(config('security.ssl_login') > 0 && isset($payload['ssl']) && $payload['ssl']) // if Our site support ssl feature and User want secure access
)
) {
Expand All @@ -122,7 +139,9 @@ protected function loadCurUserIdFromCookies()
protected function loadCurUserIdFromPasskey()
{
$passkey = app()->request->get('passkey');
if (is_null($passkey)) return false;
if (is_null($passkey)) {
return false;
}

// FIXME merge same function as tracker so
$user_id = app()->redis->zScore(Constant::mapUserPasskeyToId, $passkey);
Expand Down
24 changes: 18 additions & 6 deletions application/Components/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public function sendPM($sender, $receiver, $subject, $msg, $save = 'no', $locati
])->execute();

app()->redis->hDel(Constant::userContent($receiver), 'unread_message_count', 'inbox_count');
if ($sender != 0) app()->redis->hDel(Constant::userContent($sender), 'outbox_count');
if ($sender != 0) {
app()->redis->hDel(Constant::userContent($sender), 'outbox_count');
}
}

public function sendEmail($receivers, $subject, $template, $data = [])
Expand Down Expand Up @@ -143,7 +145,9 @@ public function ruleCategory(): array
$cats = [];
$cats_raw = app()->pdo->createCommand('SELECT * FROM `categories` WHERE `id` > 0 ORDER BY `full_path`')->queryAll();

foreach ($cats_raw as $cat_raw) $cats[$cat_raw['id']] = $cat_raw;
foreach ($cats_raw as $cat_raw) {
$cats[$cat_raw['id']] = $cat_raw;
}
app()->config->set('runtime.enabled_torrent_category', $cats, 'json');
}

Expand All @@ -164,13 +168,17 @@ public function ruleCanUsedCategory(): array

public function ruleQuality($quality): array
{
if (!in_array($quality, array_keys($this->getQualityTableList()))) throw new \RuntimeException('Unregister quality : ' . $quality);
if (!in_array($quality, array_keys($this->getQualityTableList()))) {
throw new \RuntimeException('Unregister quality : ' . $quality);
}
if (false === $data = config('runtime.enabled_quality_' . $quality)) {
$data = [];

/** @noinspection SqlResolve */
$data_raws = app()->pdo->createCommand("SELECT * FROM `quality_$quality` WHERE `id` > 0 AND `enabled` = 1 ORDER BY `sort_index`,`id`")->queryAll();
foreach ($data_raws as $data_raw) $data[$data_raw['id']] = $data_raw;
foreach ($data_raws as $data_raw) {
$data[$data_raw['id']] = $data_raw;
}
app()->config->set('runtime.enabled_quality_' . $quality, $data, 'json');
}
return $data ?: [];
Expand All @@ -181,7 +189,9 @@ public function ruleTeam(): array
if (false === $data = config('runtime.enabled_teams')) {
$data = [];
$data_raws = app()->pdo->createCommand('SELECT * FROM `teams` WHERE `id` > 0 AND `enabled` = 1 ORDER BY `sort_index`,`id`')->queryAll();
foreach ($data_raws as $data_raw) $data[$data_raw['id']] = $data_raw;
foreach ($data_raws as $data_raw) {
$data[$data_raw['id']] = $data_raw;
}
app()->config->set('runtime.enabled_teams', $data, 'json');
}

Expand Down Expand Up @@ -219,7 +229,9 @@ public function banIp($ip, $persistence = false, $commit = null)
$banips = $this->getBanIpsList();

// Add ip if not exist
if (in_array($ip, $banips)) return;
if (in_array($ip, $banips)) {
return;
}

// Rewrite config
$banips[] = $ip;
Expand Down
1 change: 0 additions & 1 deletion application/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace App\Controllers;


use Rid\Http\Controller;

class AdminController extends Controller
Expand Down
15 changes: 10 additions & 5 deletions application/Controllers/Api/v1/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace App\Controllers\Api\v1;


use Rid\Http\Controller;

class ApiController extends Controller
Expand All @@ -17,19 +16,25 @@ class ApiController extends Controller
* @param array|string $methods
* @return bool
*/
protected function checkMethod($methods) {
if (is_string($methods)) $methods = [$methods];
protected function checkMethod($methods)
{
if (is_string($methods)) {
$methods = [$methods];
}

foreach ($methods as $method) {
if (strtolower(app()->request->method()) == strtolower($method))
if (strtolower(app()->request->method()) == strtolower($method)) {
return true;
}
}
return false;
}

protected function buildMethodFailMsg($want_methods)
{
if (is_array($want_methods)) $want_methods = implode(',', $want_methods);
if (is_array($want_methods)) {
$want_methods = implode(',', $want_methods);
}

app()->response->setStatusCode(405);
$method = app()->request->method();
Expand Down
7 changes: 4 additions & 3 deletions application/Controllers/Api/v1/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

class TorrentController extends ApiController
{
public function actionBookmark() {
public function actionBookmark()
{
if ($this->checkMethod('POST')) {
$bookmark = new TorrentsForm();
$bookmark->setInput(app()->request->post());
Expand All @@ -34,7 +35,8 @@ public function actionBookmark() {
}
}

public function actionFileList() {
public function actionFileList()
{
if ($this->checkMethod('GET')) {
$filelist = new TorrentsForm();
$filelist->setInput(app()->request->get());
Expand All @@ -51,7 +53,6 @@ public function actionFileList() {
$ret
);
}

} else {
return $this->buildMethodFailMsg('GET');
}
Expand Down
1 change: 0 additions & 1 deletion application/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Rid\Http\Controller;


class AuthController extends Controller
{

Expand Down
6 changes: 4 additions & 2 deletions application/Controllers/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

class MaintenanceController extends Controller
{
public function actionIndex() {
public function actionIndex()
{
// Check if site is on maintenance status
if (!config('base.maintenance'))
if (!config('base.maintenance')) {
return app()->response->redirect('/index');
}

return $this->render('maintenance');
}
Expand Down
15 changes: 8 additions & 7 deletions application/Controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace App\Controllers;


use App\Models\Form\News;
use Rid\Http\Controller;

class NewsController extends Controller
{
public function actionIndex() {
public function actionIndex()
{
$pager = new News\SearchForm();
$pager->setInput(app()->request->get());

Expand All @@ -26,7 +26,8 @@ public function actionIndex() {
}
}

public function actionNew() {
public function actionNew()
{
if (app()->request->isPost()) {
$newform = new News\EditForm();
$newform->setInput(app()->request->post());
Expand Down Expand Up @@ -66,16 +67,16 @@ public function actionEdit()
return $this->render('action/fail', ['title' => 'Action Failed', 'msg' => 'action not allowed']);
}

public function actionDelete() {
public function actionDelete()
{
if (app()->auth->getCurUser()->isPrivilege('manage_news')) {
$id = app()->request->get('id',0);
if (filter_var($id,FILTER_VALIDATE_INT) && $id > 0) {
$id = app()->request->get('id', 0);
if (filter_var($id, FILTER_VALIDATE_INT) && $id > 0) {
// TODO add other check
app()->pdo->createCommand('DELETE FROM news WHERE id= :id')->bindParams(['id'=>$id])->execute();
}
return app()->response->redirect('/news');
}
return $this->render('action/fail', ['title' => 'Action Failed', 'msg' => 'action not allowed']);

}
}
5 changes: 2 additions & 3 deletions application/Controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace App\Controllers;


use App\Models\Form\Site;
use Rid\Http\Controller;

Expand All @@ -23,8 +22,8 @@ public function actionLogs()
{
$logs = new Site\Logs();
if (!$logs->validate()) {
return $this->render('action/fail',['msg'=>$logs->getError()]);
return $this->render('action/fail', ['msg'=>$logs->getError()]);
}
return $this->render('site/logs',['logs'=>$logs]);
return $this->render('site/logs', ['logs'=>$logs]);
}
}
2 changes: 1 addition & 1 deletion application/Controllers/SubtitlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function actionDelete()
return $this->render('action/fail', ['msg' => $delete->getError()]); // TODO add redirect
} else {
$delete->flush();
return $this->render('action/success',['redirect' => '/subtitles']); // TODO add redirect
return $this->render('action/success', ['redirect' => '/subtitles']); // TODO add redirect
}
}
}
2 changes: 0 additions & 2 deletions application/Controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class TorrentsController extends Controller
{

public function actionIndex()
{
return $this->actionSearch();
Expand Down Expand Up @@ -47,6 +46,5 @@ public function actionTags()
}
return $this->render('torrents/tags', ['pager' => $pager]);
}

}
}
Loading

0 comments on commit e734812

Please sign in to comment.