2017-08-21 20 views
0

Laravelの正式な足場でパスワードをリセットするためのデフォルトの検証を無効にするにはどうすればよいですか?Laravel 5.4:リセットパスワードの有効化をカスタマイズできません

私はResetsPasswordsトレイトから、私のResetPasswordControllerに、以下の方法コピーした:私は、例えば、ルールを削除すると

public function reset(Request $request) 
{ 
    $this->validate($request, $this->rules(), $this->validationErrorMessages()); 

    // Here we will attempt to reset the user's password. If it is successful we 
    // will update the password on an actual user model and persist it to the 
    // database. Otherwise we will parse the error and return the response. 
    $response = $this->broker()->reset(
     $this->credentials($request), function ($user, $password) { 
      $this->resetPassword($user, $password); 
     } 
    ); 

    // If the password was successfully reset, we will redirect the user back to 
    // the application's home authenticated view. If there is an error we can 
    // redirect them back to where they came from with their error message. 
    return $response == Password::PASSWORD_RESET 
       ? $this->sendResetResponse($response) 
       : $this->sendResetFailedResponse($request, $response); 
} 

/** 
* Get the password reset validation rules. 
* 
* @return array 
*/ 
protected function rules() 
{ 
    return [ 
     'token' => 'required', 
     'email' => 'required|email', 
     'password' => 'required|confirmed|min:6', 
    ]; 
} 

を長さが6文字未満のパスワードを使用すると、 'min:6'エラーメッセージが返されます。

私は関連するドキュメントに言及しましたが、私はそれから必要なものを取ることができませんでした。

お手数をおかけしますようお願い申し上げます。

答えて

1

$this->validateメソッドを使用しているため、検証処理が完全に制御されていないため、問題が検証から来ていると思います。

通常、ResetPasswordControllerの検証ルールを上書きすると問題が解決されています。ちょっと

Route::post('/reset-password', [ 
    'uses'=>'Auth\[email protected]', 
    'as' => 'reset' 
]); 
+0

:あなたはあなたが使用することができ、右ルート を使用していることを確認:ここ

たちはAuth\ResetPasswordController

public function reset(Request $request) { $validator = validator($request->all(), [ 'token' => 'required', 'email' => 'required|email', 'password' => 'required|confirmed|min:6', ], $this->validationErrorMessages()); if($validator->fails()) { //do stuffs here like return redirect()->back()->withErrors($validator); } //if we get here means validation passed :) so lets allow these to continue // Here we will attempt to reset the user's password. If it is successful we // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { $this->resetPassword($user, $password); } ); // If the password was successfully reset, we will redirect the user back to // the application's home authenticated view. If there is an error we can // redirect them back to where they came from with their error message. if($response == Password::PASSWORD_RESET) { //means password reset was successful return redirect()->to('/dashboard'); }else{ //means reset failed return redirect()->back() ->withInput($request->only('email')) ->withErrors(['email' => trans($response)]); } } 

NBにフルコントロールを持つことができますので、のは、直接Validatorクラスを使用してみましょう、別の方法です、 ご協力いただきありがとうございます。私は上記をテストして、フォームはまだ私が削除したバリデーションルールからエラーを返すようですが、応答変数がこの原因であるようです。 –