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


Messages In This Thread
Find Bug in CI4 - by paliz - 10-08-2020, 10:35 PM
RE: Find Bug in CI4 - by paliz - 10-09-2020, 02:17 AM
RE: Find Bug in CI4 - by InsiteFX - 10-09-2020, 10:16 PM
RE: Find Bug in CI4 - by paliz - 10-09-2020, 10:50 PM
RE: Find Bug in CI4 - by InsiteFX - 10-10-2020, 03:14 AM
RE: Find Bug in CI4 - by paliz - 10-10-2020, 07:54 AM
RE: Find Bug in CI4 - by paulbalandan - 10-10-2020, 12:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB