URLで変数を持つLaravel Route
-
21-12-2019 - |
質問
パスワードリセットロジックを実装しようとしています。ユーザーはリンクを入手して電子メールのパスワードをリセットします。 URLは
のように見えますhttp://example.com/reset/resetcode
.
私はそれに対して定義された経路を持っています:
Route::get('reset/{resetcode}', function(){
return View::make('users.reset_password');
});
.
フォームを表示するためにフォームがemail, new password
などを送信するために、
Route::post('reset/{resetcode}', array( 'as' => 'reset', 'uses' => 'UserController@passwordReset'));
.
resetcode
からpost route
を
public function passwordReset($resetcode)
{
$validation = Validator::make(Input::all(), UserModel::$rulesPasswordReset);
if ($validation->passes())
{
try
{
// Find the user using the user email address
$user = Sentry::findUserByLogin(Input::get('email'));
// Check if the reset password code is valid
if ($user->checkResetPasswordCode($resetcode))
{
// Attempt to reset the user password
if ($user->attemptResetPassword($resetcode, 'new_password'))
{
// Password reset passed
}
else
{
// Password reset failed
}
}
else
{
// The provided password reset code is Invalid
}
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
echo 'User was not found.';
}
}
else return Redirect::route('reset')->withInput()
->withErrors($validation)
->with('title', 'resetrequestfailure')
->with('message', 'Seems like you made some errors.');
}
.
検証が失敗した後にpasswordReset
を実行したときの問題は、 Redirect::route
に定義されているルートからresetcode
を取得しています。検証が失敗すると、リダイレクトルートはメッセージをめくると、2回目にpost
を取得できません。想定されるフォーマットのURL
http://example.com/reset/8f1Z7wA4uVt7VemBpGSfaoI9mcjdEwtK8elCnQOb
.
が
になりますhttp://bcnet.org/reset/%7Bcode%7D
.
経路のresetcode
部分と関係があり、これは可変であるため、検証が失敗した後でも正しい/{resetcode}
を取得できます。または、検証失敗後に適切なresetcode
に固定できますか。
解決
あなたのreturnに$resetcode
を含める必要があります
else return Redirect::route('reset', $resetcode)->withInput()
->withErrors($validation)
. 所属していません StackOverflow