-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: ValidationRules::buildUserFromRequest()
does not support json input
#612
Comments
Here is how you can do it. I'm not using it with User entity, but it can be the same. You need to initialise I'm using something like this within API /**
* Validate POST data
*/
if (! $this->validate($this->getUserValidationRules())) {
log_message('error', implode(', ', $this->validator->getErrors()));
return $this->fail($this->validator->getErrors());
}
$user = new User();
$user = $user->fill($this->request->getJSON() ? $this->request->getJSON(true) : $this->request->getVar()); |
ValidationRules::buildUserFromRequest()
does not support json input
I kind of dislike the implementation where the ValidationRule depends on the Request. |
Can you explain? What do you mean by this? There is a strong_password validation rule for the password input field available in shield. How else I should use the ValidationRule? |
In my opinion a validation rule just validates value(s). |
@ValdisM Please try: $this->validation->setRules([
"email" => ["label" => "Email", "rules" => "required|max_length[254]|valid_email"],
"newPassword" => ["label" => "New password", "rules" => "required|strong_password[]"],
"newPasswordAgain" => ["label" => "Repeat password", "rules" => "required|matches[newPassword]"],
]); |
This issue still persists. I've tried to update this:
to: $data = $request->getVar($fields); and also tried @kenjis recommendation, i.e., using
|
str_contains() requires PHP 8.0 or later. |
The How about this?
Is it not better written as: $data = $request->getVar($fields); so it can support all request types? |
PHP Version
8
CodeIgniter4 Version
4.3.0
Shield Version
dev-develop
Which operating systems have you tested for this bug?
macOS
Which server did you use?
apache
Database
MariaDB
Did you customize Shield?
What happened?
buildUserFromRequest support only form data inputs, not json input from service("request").
Before:
After:
Steps to Reproduce
it was catched when "strong_password" rule was applied.
Expected Output
Anything else?
No response
The text was updated successfully, but these errors were encountered: