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

Commit

Permalink
style(Bencode): Move Bencode library to App\Library but not part of f…
Browse files Browse the repository at this point in the history
…ramework
  • Loading branch information
Rhilip committed Sep 13, 2019
1 parent b825eca commit 01abc98
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- **Search:** Search keywords in NPHP ways (ccde9c0)
- **Torrent/Comment:** Fix user can't see anonymous uploader's comment (bd2d821)
- **User:** Fix User Class miss in string format (3680444)
- **fix:** Fix torrent can't upload after last commits (69fdce9)

### Perf
- **Auth/Login:** Simple The Auth Login Fail (6f11931)
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ public function rulePinnedTags(): array

public function getBanIpsList(): array
{
$ban_ips = config('runtime.ban_ips_list');
if ($ban_ips === false) {
if (false === $ban_ips = config('runtime.ban_ips_list')) {
$ban_ips = app()->pdo->createCommand('SELECT `ip` FROM `ban_ips`')->queryColumn() ?: [];
app()->config->set('runtime.ban_ips_list', $ban_ips, 'json');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Libraries\Constant;
use App\Models\User;
use Rid\Utils\IpUtils;
use Rid\Bencode\Bencode;
use App\Libraries\Bencode\Bencode;

use App\Exceptions\TrackerException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Time: 20:00
*/

namespace Rid\Bencode;
namespace App\Libraries\Bencode;


class Bencode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 20:27
*/

namespace Rid\Bencode;
namespace App\Libraries\Bencode;


class ParseErrorException extends \RuntimeException
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/GeoIP/GeoIPInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/** TODO
* Created by PhpStorm.
* User: Rhilip
* Date: 8/13/2019
Expand Down
13 changes: 10 additions & 3 deletions src/Models/Form/Auth/UserRegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function isValidUsername()

// Check if this username is not in blacklist
if (!app()->redis->exists('site:username_ban_list')) {
$ban_username_list = app()->pdo->createCommand('SELECT `username` from `ban_usernames`')->queryColumn();
$ban_username_list = app()->pdo->createCommand('SELECT `username` from `ban_usernames`')->queryColumn() ?: [];
app()->redis->hMset('site:username_ban_list', $ban_username_list);
app()->redis->expire('site:username_ban_list', 86400);
}
Expand All @@ -178,7 +178,7 @@ protected function isValidUsername()

// Check this username is exist in Table `users` or not
$count = app()->pdo->createCommand("SELECT COUNT(`id`) FROM `users` WHERE `username` = :username")->bindParams([
"username" => $username
'username' => $username
])->queryScalar();
if ($count > 0) {
$this->buildCallbackFailMsg('ValidUsername', "The user name `$username` is already used.");
Expand Down Expand Up @@ -282,13 +282,15 @@ public function flush()
if (app()->site::fetchUserCount() == 0) {
$this->status = User::STATUS_CONFIRMED;
$this->class = User::ROLE_STAFFLEADER;
$this->confirm_way = "auto";
$this->confirm_way = 'auto';
}

// User status should be confirmed if site confirm_way is auto
if ($this->confirm_way == 'auto' and $this->status != User::STATUS_CONFIRMED) {
$this->status = User::STATUS_CONFIRMED;
}

// Insert into `users` table and get insert id
app()->pdo->createCommand("INSERT INTO `users` (`username`, `password`, `email`, `status`, `class`, `passkey`, `invite_by`, `create_at`, `register_ip`, `uploadpos`, `downloadpos`, `uploaded`, `downloaded`, `seedtime`, `leechtime`, `bonus_other`,`invites`)
VALUES (:name, :passhash, :email, :status, :class, :passkey, :invite_by, CURRENT_TIMESTAMP, INET6_ATON(:ip), :uploadpos, :downloadpos, :uploaded, :downloaded, :seedtime, :leechtime, :bonus, :invites)")->bindParams(array(
'name' => $this->username, 'passhash' => password_hash($this->password, PASSWORD_DEFAULT), 'email' => $this->email,
Expand All @@ -301,8 +303,11 @@ public function flush()
))->execute();
$this->id = app()->pdo->getLastInsertId();

// TODO Newcomer exams

$log_text = "User $this->username($this->id) is created now.";

// Send Invite Success PM to invitee
if ($this->type == 'invite') {
app()->pdo->createCommand("UPDATE `invite` SET `used` = 1 WHERE `hash` = :invite_hash")->bindParams([
"invite_hash" => $this->invite_hash,
Expand All @@ -314,6 +319,7 @@ public function flush()
app()->site->sendPM(0, $this->invite_by, 'New Invitee Signup Successful', "New Invitee Signup Successful");
}

// Send Confirm Email
if ($this->confirm_way == 'email') {
$confirm_key = StringHelper::getRandomString(32);
app()->pdo->createCommand('INSERT INTO `user_confirm` (`uid`,`secret`,`create_at`,`action`) VALUES (:uid,:secret,CURRENT_TIMESTAMP,:action)')->bindParams([
Expand All @@ -331,6 +337,7 @@ public function flush()
]);
}

// Add Site log for user signup
app()->site->writeLog($log_text, app()->site::LOG_LEVEL_MOD);
}
}
2 changes: 1 addition & 1 deletion src/Models/Form/Torrent/DownloadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace App\Models\Form\Torrent;

use App\Models\Form\Traits\FileSentTrait;
use Rid\Bencode\Bencode;
use App\Libraries\Bencode\Bencode;

class DownloadForm extends StructureForm
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Form/Torrent/StructureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace App\Models\Form\Torrent;

use App\Libraries\Constant;
use Rid\Bencode\Bencode;
use App\Libraries\Bencode\Bencode;

class StructureForm extends DetailsForm
{
Expand Down
19 changes: 13 additions & 6 deletions src/Models/Form/Torrents/UploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Rid\Http\UploadFile;
use Rid\Validators\Validator;

use Rid\Bencode\Bencode;
use Rid\Bencode\ParseErrorException;
use App\Libraries\Bencode\Bencode;
use App\Libraries\Bencode\ParseErrorException;

class UploadForm extends Validator
{
Expand Down Expand Up @@ -162,7 +162,14 @@ public static function inputRules(): array

public static function callbackRules(): array
{
return ['isValidTorrentFile', 'makePrivateTorrent'];
return ['checkUploadPos', 'isValidTorrentFile', 'makePrivateTorrent'];
}

/** @noinspection PhpUnused */
protected function checkUploadPos()
{
if (!app()->auth->getCurUser()->getUploadpos())
$this->buildCallbackFailMsg('pos','your upload pos is disabled');
}

/** @noinspection PhpUnused */
Expand Down Expand Up @@ -449,12 +456,12 @@ private function getFileTree()
return json_encode($structure);
}

private static function makeFileTree($array, $delimiter = '/')
private static function makeFileTree(array $array, $delimiter = '/')
{
if (!is_array($array)) return array();
if (!is_array($array)) return [];

$splitRE = '/' . preg_quote($delimiter, '/') . '/';
$returnArr = array();
$returnArr = [];
foreach ($array as $key => $val) {
// Get parent parts and the current leaf
$parts = preg_split($splitRE, $key, -1, PREG_SPLIT_NO_EMPTY);
Expand Down
2 changes: 1 addition & 1 deletion templates/torrent/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @var \App\Models\Form\Torrent\StructureForm $structure
*/

use Rid\Bencode\Bencode;
use App\Libraries\Bencode\Bencode;

if (!function_exists('torrent_structure_builder')) {
function torrent_structure_builder($array, $parent = "")
Expand Down

0 comments on commit 01abc98

Please sign in to comment.