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

Commit

Permalink
refactor(Validator): fix user input extract
Browse files Browse the repository at this point in the history
1. Fix user input extract in Validator, remove limit to extract user input to only defined public value. Now only prevent {private, protected, static} property will not be rewrite by user input.
2. Fix input file lost record in array `_file_input_name`.
3. Remove function buildDefaultDataForValid(), now we rewrite array `_input` by `array_merge(static::defaultData(), $this->_input);` at start of validate(); Remove function buildDefaultPropBeforeValid() (may revert); Rename function `setData` -> `setInput`, `getData` -> `getInput`.
4. Add Min Limit for PagerTrait.
5. move route `/user` alias `/user/details` but not `/user/panel`
6. Limit user init, the time and ip information ({creat,last_{login,access,upload,download,connect}}_at, {register,last_{login,access,tracker}}_ip) will not get from database.
  • Loading branch information
Rhilip committed Aug 13, 2019
1 parent db6d5ff commit 81bdc8f
Show file tree
Hide file tree
Showing 49 changed files with 433 additions and 456 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
- **template:** Add git commit hash in `CHANGELOG.md` (76bc527)

### Feat
- **Auth:** Sep Auth part from Site to new components (f36884e)
- **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)
- **ban_ips:** Store banned ip in components/Site (01084c9)

Expand All @@ -33,6 +34,9 @@
- **torrent/structure:** Use zui.tree instead javascript `$(this).next('ul').toggle()` (7b20b2c)
- **view:** Fix helper/username params (720f37e)

### Revert
- **Redis:** Remove view in redis , use other software install (c5d3378)


<a name="v0.1.5-alpha"></a>
## [v0.1.5-alpha] - 2019-08-09
Expand Down
6 changes: 3 additions & 3 deletions apps/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function actionRegister()
{
if (app()->request->isPost()) {
$register_form = new Auth\UserRegisterForm();
$register_form->setData(app()->request->post());
$register_form->setInput(app()->request->post());
$success = $register_form->validate();
if (!$success) {
return $this->render('action/action_fail', [
Expand All @@ -48,7 +48,7 @@ public function actionRegister()
public function actionConfirm()
{
$confirm = new Auth\UserConfirmForm();
$confirm->setData(app()->request->get());
$confirm->setInput(app()->request->get());
$success = $confirm->validate();
if (!$success) {
return $this->render('action/action_fail', [
Expand All @@ -68,7 +68,7 @@ public function actionRecover()
{
if (app()->request->isPost()) {
$form = new Auth\UserRecoverForm();
$form->setData(app()->request->post());
$form->setInput(app()->request->post());
$success = $form->validate();
if (!$success) {
return $this->render('action/action_fail', [
Expand Down
6 changes: 3 additions & 3 deletions apps/controllers/LinksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function actionApply()
{
if (app()->request->isPost()) {
$form = new Links\ApplyForm();
$form->setData(app()->request->post());
$form->setInput(app()->request->post());
$success = $form->validate();
if ($success) {
$form->flush();
Expand All @@ -40,7 +40,7 @@ public function actionManage()
if (app()->request->isPost()) {
if (app()->request->post('action') == 'link_edit') {
$edit_form = new Links\EditForm();
$edit_form->setData(app()->request->post());
$edit_form->setInput(app()->request->post());
$success = $edit_form->validate();
if ($success) {
$edit_form->flush();
Expand All @@ -50,7 +50,7 @@ public function actionManage()
}
} elseif (app()->request->post('action') == 'link_delete') {
$delete_form = new Links\RemoveForm();
$delete_form->setData(app()->request->post());
$delete_form->setInput(app()->request->post());
$success = $delete_form->validate();
if ($success) {
$delete_form->flush();
Expand Down
4 changes: 2 additions & 2 deletions apps/controllers/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function actionCategories()
if (app()->request->isPost()) {
if (app()->request->post('action') == 'cat_edit') {
$edit_form = new Categories\EditForm();
$edit_form->setData(app()->request->post());
$edit_form->setInput(app()->request->post());
$success = $edit_form->validate();
if ($success) {
$edit_form->flush();
Expand All @@ -28,7 +28,7 @@ public function actionCategories()
}
} elseif (app()->request->post('action') == 'cat_delete') {
$delete_form = new Categories\RemoveForm();
$delete_form->setData(app()->request->post());
$delete_form->setInput(app()->request->post());
$success = $delete_form->validate();
if ($success) {
$delete_form->flush();
Expand Down
6 changes: 3 additions & 3 deletions apps/controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NewsController extends Controller
{
public function actionIndex() {
$pager = new News\SearchForm();
$pager->setData(app()->request->get());
$pager->setInput(app()->request->get());

$success = $pager->validate();
if (!$success) {
Expand All @@ -29,7 +29,7 @@ public function actionIndex() {
public function actionNew() {
if (app()->request->isPost()) {
$newform = new News\EditForm();
$newform->setData(app()->request->post());
$newform->setInput(app()->request->post());
$success = $newform->validate();
if (!$success) {
return $this->render('action/action_fail', ['title' => 'new blog failed', 'msg' => $newform->getError()]);
Expand All @@ -47,7 +47,7 @@ public function actionEdit()
{
if (app()->request->isPost()) {
$newform = new News\EditForm();
$newform->setData(app()->request->post());
$newform->setInput(app()->request->post());
$success = $newform->validate();
if (!$success) {
return $this->render('action/action_fail', ['title' => 'Upload Failed', 'msg' => $newform->getError()]);
Expand Down
2 changes: 1 addition & 1 deletion apps/controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function actionDetails()
$details = new Torrent\DetailsForm();
$success = $details->validate();
if (!$success) {
return $this->render('action/action_fail');
return $this->render('action/action_fail', ['msg' => $details->getError()]);
}

return $this->render('torrent/details', ['details' => $details]);
Expand Down
10 changes: 5 additions & 5 deletions apps/controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function actionSearch()
{
// TODO add URI level Cache
$pager = new Torrents\SearchForm();
$pager->setData(app()->request->get());
$pager->setInput(app()->request->get());
$success = $pager->validate();
if (!$success) {
return $this->render('action/action_fail');
Expand All @@ -38,8 +38,8 @@ public function actionUpload()
// TODO Check user upload pos
if (app()->request->isPost()) {
$uploadForm = new Torrents\UploadForm();
$uploadForm->setData(app()->request->post());
$uploadForm->setFileData(app()->request->files());
$uploadForm->setInput(app()->request->post());
$uploadForm->setFileInput(app()->request->files());
$success = $uploadForm->validate();
if (!$success) {
return $this->render('action/action_fail', ['title' => 'Upload Failed', 'msg' => $uploadForm->getError()]);
Expand All @@ -50,7 +50,7 @@ public function actionUpload()
return $this->render('action/action_fail', ['title' => 'Upload Failed', 'msg' => $e->getMessage()]);
}

return app()->response->redirect('/torrent/details?id=' . $uploadForm->id);
return app()->response->redirect('/torrent/details?id=' . $uploadForm->getId());
}
} else {
return $this->render('torrents/upload');
Expand All @@ -61,7 +61,7 @@ public function actionUpload()
public function actionTags()
{
$pager = new Torrents\TagsForm();
$pager->setData(app()->request->get());
$pager->setInput(app()->request->get());
$success = $pager->validate();

if (!$success) {
Expand Down
19 changes: 9 additions & 10 deletions apps/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UserController extends Controller

public function actionIndex()
{
return $this->actionPanel();
return $this->actionDetails();
}

public function actionSetting()
Expand All @@ -30,7 +30,7 @@ public function actionInvite()
$msg = '';
if (app()->request->isPost()) {
$form = new User\InviteForm();
$form->setData(app()->request->post());
$form->setInput(app()->request->post());
$success = $form->validate();
if ($success) {
$form->flush();
Expand All @@ -53,7 +53,7 @@ public function actionInvite()
// FIXME By using Form Class
if (!is_null(app()->request->get('action'))) {
$action_form = new User\InviteActionForm();
$action_form->setData(app()->request->get());
$action_form->setInput(app()->request->get());
$success = $action_form->validate();
if ($success) {
$msg = $action_form->flush();
Expand All @@ -66,15 +66,14 @@ public function actionInvite()
}


public function actionPanel()
public function actionDetails()
{
$uid = app()->request->get('id');
if ($uid && $uid != app()->auth->getCurUser()->getId()) {
$user = app()->site->getUser($uid);
} else {
$user = app()->auth->getCurUser();
$panel = new User\UserDetailsForm();
if (!$panel->validate()) {
return $this->render('action/action_fail', ['msg' => $panel->getError()]);
}
return $this->render('user/panel', ['user' => $user]);

return $this->render('user/details', ['details' => $panel]);
}

public function actionSessions()
Expand Down
6 changes: 3 additions & 3 deletions apps/controllers/api/v1/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TorrentController extends ApiController
public function actionBookmark() {
if ($this->checkMethod('POST')) {
$bookmark = new TorrentsForm();
$bookmark->setData(app()->request->post());
$bookmark->setInput(app()->request->post());
$success = $bookmark->validate();
if (!$success) {
return [
Expand All @@ -38,7 +38,7 @@ public function actionBookmark() {
public function actionFileList() {
if ($this->checkMethod('GET')) {
$filelist = new TorrentsForm();
$filelist->setData(app()->request->get());
$filelist->setInput(app()->request->get());
$success = $filelist->validate();
if (!$success) {
return [
Expand All @@ -62,7 +62,7 @@ public function actionNfoFileContent()
{
if ($this->checkMethod('GET')) {
$filelist = new TorrentsForm();
$filelist->setData(app()->request->get());
$filelist->setInput(app()->request->get());
$success = $filelist->validate();
if (!$success) {
return [
Expand Down
15 changes: 15 additions & 0 deletions apps/libraries/GeoIP/GeoIPInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: Rhilip
* Date: 8/13/2019
* Time: 2019
*/

namespace apps\libraries\GeoIP;


interface GeoIPInterface
{
public static function getLocation();
}
Loading

0 comments on commit 81bdc8f

Please sign in to comment.