Browse Source

* added method for sanitizing POST in all application

Giancarlo Voci 8 years ago
parent
commit
7d5e58091c
2 changed files with 15 additions and 7 deletions
  1. 12 4
      src/Modules/BaseController.php
  2. 3 3
      src/Modules/Pages.php

+ 12 - 4
src/Modules/BaseController.php

@@ -11,9 +11,20 @@ class BaseController
 {
 {
   protected $dbHandle;
   protected $dbHandle;
   protected $userId;
   protected $userId;
+  private $sanitizedPostRequest;
+
+  /**
+   * @return mixed
+   */
+  public function getSanitizedPostRequest()
+  {
+    return $this->sanitizedPostRequest;
+  }
 
 
   public function __construct($f3)
   public function __construct($f3)
   {
   {
+    $this->sanitizedPostRequest = $f3->clean($f3->get('POST'));
+
     $this->dbHandle = $f3->get('DB');
     $this->dbHandle = $f3->get('DB');
 
 
     $this->userId = $this->checkLogin($f3->get('COOKIE.username'), $f3->get('COOKIE.password'));
     $this->userId = $this->checkLogin($f3->get('COOKIE.username'), $f3->get('COOKIE.password'));
@@ -51,9 +62,7 @@ class BaseController
 
 
   public function Login($f3)
   public function Login($f3)
   {
   {
-    $f3->clear('SESSION');
-
-    $accountData = $f3->clean($f3->get('POST'));
+    $accountData = $this->getSanitizedPostRequest();
 
 
     $userId = $this->checkLogin($accountData['username'], $accountData['password']);
     $userId = $this->checkLogin($accountData['username'], $accountData['password']);
 
 
@@ -72,7 +81,6 @@ class BaseController
 
 
   public function Logout($f3)
   public function Logout($f3)
   {
   {
-    $f3->clear('SESSION');
     $f3->clear('COOKIE.username');
     $f3->clear('COOKIE.username');
     $f3->clear('COOKIE.password');
     $f3->clear('COOKIE.password');
     $f3->clear('COOKIE.id');
     $f3->clear('COOKIE.id');

+ 3 - 3
src/Modules/Pages.php

@@ -44,7 +44,7 @@ class Pages extends BaseController
       $f3->clear('COOKIE.consegna');
       $f3->clear('COOKIE.consegna');
       $f3->clear('COOKIE.labelid');
       $f3->clear('COOKIE.labelid');
     } else {
     } else {
-      $stepValues = array_map('strtoupper', $f3->get('POST'));
+      $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
       if (count($stepValues) == 0)
       if (count($stepValues) == 0)
         $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
         $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
     }
     }
@@ -152,7 +152,7 @@ class Pages extends BaseController
     if ($args['step'] == 1)
     if ($args['step'] == 1)
       $f3->clear('COOKIE.bind');
       $f3->clear('COOKIE.bind');
     else {
     else {
-      $stepValues = array_map('strtoupper', $f3->get('POST'));
+      $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
       if (count($stepValues) == 0)
       if (count($stepValues) == 0)
         $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
         $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
     }
     }
@@ -211,7 +211,7 @@ class Pages extends BaseController
 
 
   public function UnBind($f3, array $args)
   public function UnBind($f3, array $args)
   {
   {
-    $stepValues = array_map('strtoupper', $f3->get('POST'));
+    $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
     if ($args['step'] == 2) {
     if ($args['step'] == 2) {
       $success = $this->findBoxCore->UnBind($stepValues['labelid']);
       $success = $this->findBoxCore->UnBind($stepValues['labelid']);
       if ($success['err'] <> 0) {
       if ($success['err'] <> 0) {