Skip to content
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

User edit: Default empty password behavior #351

Closed
gvanto opened this issue Jan 18, 2024 · 7 comments
Closed

User edit: Default empty password behavior #351

gvanto opened this issue Jan 18, 2024 · 7 comments

Comments

@gvanto
Copy link

gvanto commented Jan 18, 2024

Bug report

What I did:

Left password empty and tried saving user.

What I expected to happen:

Ignores the password entirely (ie dont try and update it. If I am editing a user I don't necessarily want to update their password)

What happened:

Error thrown:
image

Backpack, Laravel, PHP, DB version:

BP/Crud 6.4, Lara 10.x, MySQL 5.7

@pxpm
Copy link
Contributor

pxpm commented Jan 18, 2024

Hey there.

I could not reproduce your use case. Can you reproduce it in our online demo ?

Cheers

@gvanto
Copy link
Author

gvanto commented Jan 19, 2024

Hi @pxpm

Ok I tried the online demo but it says "user editing is disable for demo" so maybe that's why it's not throwing the same error?

@gvanto
Copy link
Author

gvanto commented Jan 19, 2024

@gvanto
Copy link
Author

gvanto commented Jan 19, 2024

Actually I'm thinking this is not a validation issue ... as it doesn't come up with form validation error.

It's almost as if the empty string (password + confirm) are not being converted to null (I've checked though and the ConvertEmptyStringsToNull middleware is in the call stack on the error page)

Very strange, let me investigate some more ...

@gvanto
Copy link
Author

gvanto commented Jan 19, 2024

Ok found the issue, had 'password' in my $fillable array on my User model (needed in other places) which was causing the issue ... sorry for that and thanks again for your help @pxpm

@gvanto gvanto closed this as completed Jan 19, 2024
@gvanto
Copy link
Author

gvanto commented Feb 11, 2024

Ok found the issue, had 'password' in my $fillable array on my User model (needed in other places) which was causing the issue ... sorry for that and thanks again for your help @pxpm

This wasn't the issue ('password' should be fillable on the User model: https://github.com/laravel/laravel/blob/10.x/app/Models/User.php#L23 )

So I'm still facing this same issue. On leaving the password empty, the error is thrown as per the first post ...(password not nullable).

When I output the request's contents: (in UpdateOperation > update()):
The password and password_confirmation are null (as expected).

array:12 [▼ // vendor/backpack/crud/src/app/Http/Controllers/Operations/UpdateOperation.php:91
  "_token" => "X7YFNVKS0vSBdWirYZgk3A2fNRQktOFn6NKqPFSi"
  "_method" => "PUT"
  "_http_referrer" => "http://0.0.0.0:8000/admin/user"
  "name" => "Gert"
  "email" => "gert@email.com"
  "password" => null
  "password_confirmation" => null
  "roles" => array:1 [▶]
  "roles_show" => array:1 [▶]
  "permissions" => null
  "id" => "2"
  "_save_action" => "save_and_back"
]

What is strange is why this query is being run at all? (the password is the only field that should not be updated, as it was left blank):

image

@gvanto gvanto reopened this Feb 11, 2024
@promatik
Copy link
Contributor

promatik commented Apr 7, 2024

Hey @gvanto!
You can try to clone demo to your local machine and try this, locally it will work as expected.

I tried our demo (locally) and everything works as expected.

image
The password is sent as empty, but it's not updated.

My guess is maybe you're not using ConvertEmptyStringsToNull middleware, or maybe there's a mutator for the password in your model. Can you share with us your user controller and model?

I'll close this issue for now, but please feel free to leave us your questions and keep us up to date 🙌

@promatik promatik closed this as completed Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants
@promatik @pxpm @gvanto and others