Welcome Guest, Not a member yet? Register   Sign In
Find Bug in CI4
#1

(This post was last modified: 10-08-2020, 10:48 PM by paliz.)

 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  
Enlightenment  Is  Freedom
Reply
#2

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
Enlightenment  Is  Freedom
Reply
#3

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?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(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)
}
Enlightenment  Is  Freedom
Reply
#5

Glad you got it fixed.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(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
Enlightenment  Is  Freedom
Reply
#7

(This post was last modified: 10-10-2020, 12:21 PM by paulbalandan.)

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB