AchrafReyani / educom-webshop-oop

0 stars 0 forks source link

Deze functie doet meer dan zijn naam doet vermoeden, beter een nieuwe naam geven #24

Open JeroenHeemskerk opened 4 months ago

JeroenHeemskerk commented 4 months ago

Onderstaande functie https://github.com/AchrafReyani/educom-webshop-oop/blob/94f640cb74d03d8a00558191f593a082ba3aae81/models/PageModel.php#L26-L33

Haalt niet alleen de data uit de $_GET maar ook uit de $_POST, een naam als getRequestVar zou beter op zijn plek zijn.

Daarnaast zou ik de $this->isPost variabele gebruiken dus dan wordt het:

   protected function getRequestVar($key, $default = "") { 
     if ($this->isPost) { 
       $value = isset($_POST[$key]) ? trim($_POST[$key]) : $default; 
     } else { 
       $value = isset($_GET[$key]) ? trim($_GET[$key]) : $default; 
     } 
     return $value; 
   } 

en in plaats van alleen trim() zou ik een $this->testInput() functie gebruiken, zoals onderaan de W3Schools pagina over form validatie wordt gebruikt.


Je kan deze functie dan gelijk gebruiken op deze plekken https://github.com/AchrafReyani/educom-webshop-oop/blob/94f640cb74d03d8a00558191f593a082ba3aae81/models/ShopModel.php#L16 wordt dan

 $id = getRequestVar('id', 0); 

https://github.com/AchrafReyani/educom-webshop-oop/blob/94f640cb74d03d8a00558191f593a082ba3aae81/models/ShopModel.php#L39-L44 wordt dan

 public function handleCartActions() { 
   $action = getRequestVar('action'); 

en overal in de UserModel waar je nu $_POST gebruikt

https://github.com/AchrafReyani/educom-webshop-oop/blob/94f640cb74d03d8a00558191f593a082ba3aae81/models/UserModel.php#L45-L60 wordt dan

public function validateLogin() {
    if ($this->isPost) {
      $this->email = getRequestVar("email");
      if (empty($this->email)) {
        $this->emailError = "Email is required";
      }

      $this->password = getRequestVar("password");
      if (empty($_POST["password"])) {
        $this->passwordError = "Password is required";
      }

      // TODO: Add 'if' all errors are empty here before authenticating 
      $this->authenticateUser();
    }    
  }

▶️ idem in validateForm, validateChangePassword en validateRegister

JeroenHeemskerk commented 4 months ago

Dit issue is nog niet compleet.

Zoek door je hele project naar $_POST en $_GET en verwijs overal naar deze functie