CodeIgniter Forums
Find Bug in CI4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: Find Bug in CI4 (/thread-77713.html)



Find Bug in CI4 - paliz - 10-08-2020

 hi i m huge fan ci4 
i was facing issue which pin  in ass but  solve it Smile 

i  figure out which CI4 can not validate Ajax request (JSON  Raw Input) with Postman or Angular 9 

i was customizing Math/Auth for RestFull  API JWT Authentication
 i got error which can not validate Raw Input JSON     
heres part of  code  auth controoler  

 
Code:
if ($this->request->isAJAX()) {


            /**
            * Attempts to verify the user's credentials
            * through a POST request.
            */
            $rules = [
                'login' => 'required',
                'password' => 'required',
            ];

            $config = config('Myth\Auth\Config\Auth');


            if ($config->validFields == ['email']) {
                $rules['login'] .= '|valid_email';
            };


 i connot validate And Got Error I dont send login and password   



Code:
            if (!$this->validate($rules)) {

                $responseDataModel->setToken('');
                $responseDataModel->setData($this->validator->getErrors());
                $responseDataModel->setMessage('error during login validate ');
                $responseDataModel->setSuccess(false);
                return $this->response->setJSON($responseDataModel->getRowData())->setStatusCode(400)->setContentType('application/json');
            }


          }



i  go to    validation class CI4  then function 

withRequest() 
Code:
public function withRequest(RequestInterface $request): ValidationInterface
{
    if (in_array($request->getMethod(), ['put', 'patch', 'delete'])) {
        $this->data = $request->getRawInput();
    }  else {
        $this->data = $request->getVar() ?? [];
    }


    return $this;
}


add this line  to code and fix bug easily Smile

Code:
public function withRequest(RequestInterface $request): ValidationInterface
{
    if (in_array($request->getMethod(), ['put', 'patch', 'delete'])) {
        $this->data = $request->getRawInput();
    } else if ($request->isAJAX()) {

        $this->data = $request->getJSON(true);

    } else {
        $this->data = $request->getVar() ?? [];
    }


    return $this;
}



i hope next version ci4 add this line to code 

thanks to great team ci4  


RE: Find Bug in CI4 - paliz - 10-09-2020

i m not nob user i know ci3 and ci4 very well . i have a personal website written by ci3 www.paliz3d.com
i love ci


RE: Find Bug in CI4 - InsiteFX - 10-09-2020

Did you use your web browsers developer tools F-12 console to see what is happing?

Did you send the Ajax X-Requested-With header?


RE: Find Bug in CI4 - paliz - 10-09-2020

(10-09-2020, 10:16 PM)InsiteFX Wrote: Did you use your web browsers developer tools F-12 console to see what is happing?

Did you send the Ajax X-Requested-With header?
I  write sample restful api with angular9 and use chrome and  i  got  error  which i didnot post variables 

And i test with postman with header ajax   and alao got error too 
The data sent but can not  be validate 
After  test every thing i find out data dose not pass to validation class. Add if condation  in validawith() thrn  i  fix problem  

This code ads to validation with request function 
If ($resquest->isAjax()) {

$this->data=$request->getJson(true)
}


RE: Find Bug in CI4 - InsiteFX - 10-10-2020

Glad you got it fixed.


RE: Find Bug in CI4 - paliz - 10-10-2020

(10-10-2020, 03:14 AM)InsiteFX Wrote: Glad you got it fixed.
your well come  boy 
i love  ci4  and with little help of me ci4 become better framework 
i m happy


RE: Find Bug in CI4 - paulbalandan - 10-10-2020

If this is a bug in the code you can open a new issue in the github repo for it to be addressed in the next version.