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

[5.3] Allow overriding of ResetsPasswords validation rules. #15086

Closed
danielbaylis opened this issue Aug 27, 2016 · 5 comments
Closed

[5.3] Allow overriding of ResetsPasswords validation rules. #15086

danielbaylis opened this issue Aug 27, 2016 · 5 comments

Comments

@danielbaylis
Copy link
Contributor

danielbaylis commented Aug 27, 2016

Hardcoding the validation rules directly in the ResetsPasswords reset method prevents us overriding the rules in ResetsPasswordController without overriding the entire function.

Illuminate\Foundation\Auth\ResetsPasswords
$this->validate($request, [ 'token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed|min:6', ]);

It would be nice to revert to the 5.2 approach where there was a separate method of the validation rules that we could simply override in the controller:

$this->validate($request, $this->getResetValidationRules());

This allows domain-specific validations to be used without bringing the other framework logic into the controller.

@srmklive
Copy link
Contributor

You can simply override this function in your controller, and set it accordingly. I have myself done it to be inline with how it was in 5.2.

@danielbaylis
Copy link
Contributor Author

Thank you. I had mentioned that as a solution too but was trying avoid having the response logic in my controller in case it changed in the framework in the future.

Seems like we shouldn't really be overriding the lines below. But then again, testing after framework updates would soon flag if there had been any changes :) Thanks for taking a look.

        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
            $this->resetPassword($user, $password);
        }
        );

        return $response == Password::PASSWORD_RESET
            ? $this->sendResetResponse($response)
            : $this->sendResetFailedResponse($request, $response);

@roberthunt
Copy link

I was just about the raise the same issue as I was trying to customise the validation rules for minimum password length and I agree with @danielbaylis that it would be better to not have to copy and paste the response logic into the override.

I think this decision should be reconsidered, the RegisterController provides a validator that can be customised so it seems a bit inconsistent to have to do something different for the password resets.

@danielbaylis
Copy link
Contributor Author

@roberthunt - I understand PRs have a better chance than issues, so am giving it a go with #16060.

@danielbaylis
Copy link
Contributor Author

PR #16060 was merged and resolves this. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants