Open rafinhaa opened 3 years ago
I found the cause of the problem, I had to modify the buildUserFromRequest method in the /src/Authentication/Passwords/ValidationRules.php file
protected function buildUserFromRequest()
{
$fields = $this->prepareValidFields();
if (strpos(service('request')->getHeaderLine('Content-Type'), 'application/json') !== false)
{
$data = (array) service('request')->getJSON();
$data = array_intersect_key($data, array_fill_keys($fields, null));
}else{
$data = array_filter(service('request')->getPost($fields));
}
return new User($data);
}
Is this modification acceptable?
protected function buildUserFromRequest()
{
$fields = $this->prepareValidFields();
$data = array_filter(service('request')->getPost($fields));
if (empty($data)) {
//convert request body to associative array
$data = array_intersect_key(
json_decode(service('request')->getBody(), true),
array_fill_keys($fields, null)
);
}
return new User($data);
}
so it should be better!
I think that is likely fine. If you can submit a PR for it, that would be awesome.
Hi, no news about adding this issue to the release?
If someone wants to take this on as a PR please do.
I'll do
Maybe just like this?
protected function buildUserFromRequest()
{
$fields = $this->prepareValidFields();
// $data = array_filter(service('request')->getPost($fields));
// pulling data from $_REQUEST, get rid of NULL values
// works fine with both 'form-multipart' and 'application/json' content-types
// return type is array
$data = array_filter(service('request')->getVar($fields));
return new User($data);
}
And what about Shield? Shield's code is same as Myth.
Hi, i implemented myth auth in a test api and when i try to create a new user via "application/json" i get an exception
When I send the request through "multipart/form-data" I get the registration successfully!
I investigated the myth files to find a solution to this problem, but I couldn't.
Below are the classes I used as a test:
Routes:
$routes->resource('api/v1/users');
Prints:
Codeigniter 4.1.3 PHP 7.3