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

Commit

Permalink
refactor(Entity): Move Class Torrent,User to namespace App\Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Oct 2, 2019
1 parent f06b342 commit 7814d88
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 34 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
### Docs
- **Sponsor:** Add Sponsor `MeiHeZi` (ae612e0)

### Feat
- **i18n:** Use symfony/translation and JSON format for locale (02cc251)


<a name="v0.1.6-alpha"></a>
## [v0.1.6-alpha] - 2019-09-20
Expand Down
19 changes: 10 additions & 9 deletions application/Components/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Components;

use App\Models;
use App\Entity;
use App\Libraries\Constant;

use Rid\Base\Component;
Expand All @@ -30,14 +30,14 @@ public function onRequestBefore()

public function onRequestAfter()
{
parent::onRequestAfter();
$this->logSessionInfo();
parent::onRequestAfter();
}

/**
* @param string $grant
* @param string|bool $flush
* @return Models\User|bool return False means this user is anonymous
* @return Entity\User|bool return False means this user is anonymous
*/
public function getCurUser($grant = 'cookies', $flush = false)
{
Expand All @@ -60,7 +60,7 @@ public function getGrant(): string

/**
* @param string $grant
* @return Models\User|boolean
* @return Entity\User|boolean
*/
protected function loadCurUser($grant = 'cookies')
{
Expand All @@ -71,7 +71,7 @@ protected function loadCurUser($grant = 'cookies')
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() !== Models\User::STATUS_DISABLED) // user status shouldn't be disabled
if ($curuser->getStatus() !== Entity\User::STATUS_DISABLED) // user status shouldn't be disabled
return $curuser;
}

Expand Down Expand Up @@ -106,10 +106,11 @@ protected function loadCurUserIdFromCookies()
$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 , then
((isset($payload['ssl']) && $payload['ssl'] && // if User want secure access
config('security.ssl_login') > 0 // and if Our site support ssl feature
) || config('security.ssl_login') > 1)) { // or if Our site FORCE enabled ssl feature
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') > 0 && isset($payload['ssl']) && $payload['ssl']) // if Our site support ssl feature and User want secure access
)
) {
app()->response->redirect(str_replace('http://', 'https://', app()->request->fullUrl()));
app()->response->setHeader('Strict-Transport-Security', 'max-age=1296000; includeSubDomains');
}
Expand Down
10 changes: 5 additions & 5 deletions application/Components/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Components;

use App\Models;
use App\Entity;
use App\Libraries\Mailer;
use App\Libraries\Constant;

Expand Down Expand Up @@ -48,30 +48,30 @@ public function getTorrent($tid)
if (array_key_exists($tid, $this->torrents)) {
$torrent = $this->torrents[$tid];
} else {
$torrent = new Models\Torrent($tid); // TODO Handing if this torrent id does not exist
$torrent = new Entity\Torrent($tid); // TODO Handing if this torrent id does not exist
$this->torrents[$tid] = $torrent;
}
return $torrent;
}

/**
* @param $uid
* @return Models\User|bool return False means this user is not exist
* @return Entity\User|bool return False means this user is not exist
*/
public function getUser($uid)
{
if (array_key_exists($uid, $this->users)) {
$user = $this->users[$uid];
} else {
$user = new Models\User($uid); // TODO Handing if this user id does not exist
$user = new Entity\User($uid); // TODO Handing if this user id does not exist
$this->users[$uid] = $user;
}
return $user;
}

/**
* @param $username
* @return Models\User|bool
* @return Entity\User|bool
*/
public function getUserByUserName($username)
{
Expand Down
2 changes: 1 addition & 1 deletion application/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Controllers;

use App\Models\User;
use App\Entity\User;
use App\Models\Form\Auth;

use Rid\Http\Controller;
Expand Down
2 changes: 1 addition & 1 deletion application/Controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace App\Controllers;

use App\Libraries\Constant;
use App\Models\User;
use App\Entity\User;
use Rid\Utils\IpUtils;
use App\Libraries\Bencode\Bencode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 10:10
*/

namespace App\Models;
namespace App\Entity;

use App\Libraries\Constant;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Models;
namespace App\Entity;

use Rid\Utils\AttributesImportUtils;
use Rid\Utils\ClassValueCacheUtils;
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Auth/UserConfirmForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Models\Form\Auth;

use App\Models\User;
use App\Entity\User;
use Rid\Helpers\StringHelper;
use Rid\Validators\Validator;

Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Auth/UserLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace App\Models\Form\Auth;

use App\Libraries\Constant;
use App\Models\User;
use App\Entity\User;

use Rid\Helpers\StringHelper;
use Rid\Helpers\JWTHelper;
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Auth/UserRecoverForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Models\Form\Auth;

use App\Models\User;
use App\Entity\User;
use Rid\Helpers\StringHelper;
use Rid\Validators\CaptchaTrait;
use Rid\Validators\Validator;
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Auth/UserRegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace App\Models\Form\Auth;

use App\Libraries\Constant;
use App\Models\User;
use App\Entity\User;

use Rid\Helpers\StringHelper;
use Rid\Validators\Validator;
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Torrent/EditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use App\Libraries\Constant;
use App\Models\Form\Traits\isValidTorrentTrait;
use App\Models\Torrent;
use App\Entity\Torrent;

use Rid\Http\UploadFile;
use Rid\Validators\Validator;
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Traits/isValidTorrentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace App\Models\Form\Traits;


use App\Models\Torrent;
use App\Entity\Torrent;

trait isValidTorrentTrait
{
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Traits/isValidUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Models\Form\Traits;

use App\Models\User;
use App\Entity\User;

trait isValidUserTrait
{
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/User/InviteActionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace App\Models\Form\User;

use App\Models\User;
use App\Entity\User;
use Rid\Validators\Validator;

class InviteActionForm extends Validator
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 22:37
*
* @var League\Plates\Template\Template $this
* @var \App\Models\Torrent $torrent
* @var \App\Entity\Torrent $torrent
*/
?>

Expand Down
2 changes: 1 addition & 1 deletion templates/helper/torrent_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</tr>
</thead>
<tbody>
<?php foreach ($search->getPagerData() as $torrent): /** @var \App\Models\Torrent $torrent */ ?>
<?php foreach ($search->getPagerData() as $torrent): /** @var \App\Entity\Torrent $torrent */ ?>
<tr data-tid="<?= $torrent->getId() ?>">
<td class="text-center" data-item="category" style="margin: 0;padding: 0">
<?php $cat = $torrent->getCategory(); ?>
Expand Down
2 changes: 1 addition & 1 deletion templates/helper/username.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 10:57 AM
*
* @var League\Plates\Template\Template $this
* @var App\Models\User $user
* @var App\Entity\User $user
*/

$hide = $hide ?? false;
Expand Down
2 changes: 1 addition & 1 deletion templates/layout/nav_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div id="info_block_line_1">
Welcome Back, <?= $this->insert('helper/username', ['user' => $user, 'show_badge' => true]) ?>
<span data-item="logout"><!--suppress HtmlUnknownTarget -->[<a href="/auth/logout">Logout</a>]</span>
<?php if ($user->getClass() > \App\Models\User::ROLE_FORUM_MODERATOR): ?>
<?php if ($user->getClass() > \App\Entity\User::ROLE_FORUM_MODERATOR): ?>
<span><!--suppress HtmlUnknownTarget -->[<a href="/admin">Admin Panel</a>]</span>
<?php endif; ?>
<span data-item="favour"><!--suppress HtmlUnknownTarget -->[<a href="/torrents/favour">Favour</a>]</span>
Expand Down
2 changes: 1 addition & 1 deletion templates/torrent/comments_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 8:58 PM
*
* @var array $comments
* @var \App\Models\Torrent $torrent
* @var \App\Entity\Torrent $torrent
*/

$enabled_editor = $enabled_editor ?? false;
Expand Down
2 changes: 1 addition & 1 deletion templates/torrent/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$torrent = $edit->getTorrent();

use App\Models\Torrent; ?>
use App\Entity\Torrent; ?>

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

Expand Down
4 changes: 2 additions & 2 deletions templates/user/invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 16:33
*
* @var League\Plates\Template\Template $this
* @var \App\Models\User $user
* @var \App\Entity\User $user
*/
?>

Expand Down Expand Up @@ -51,7 +51,7 @@
<td class="text-center"><?= $invitee['status'] ?></td>
<?php if (app()->auth->getCurUser()->isPrivilege('invite_manual_confirm')): ?>
<td class="text-center">
<?php if ($invitee['status'] == \App\Models\User::STATUS_PENDING): ?>
<?php if ($invitee['status'] == \App\Entity\User::STATUS_PENDING): ?>
<a class="btn btn-info btn-sm" href="?action=confirm&uid=<?= $this->e($invitee['id']) ?>" onclick="return confirm('Really?')">Confirm</a>
<?php endif ?>
</td>
Expand Down

0 comments on commit 7814d88

Please sign in to comment.