質問

パスワードリセットロジックを実装しようとしています。ユーザーはリンクを入手して電子メールのパスワードをリセットします。 URLは

のように見えます
http://example.com/reset/resetcode
.

私はそれに対して定義された経路を持っています:

Route::get('reset/{resetcode}', function(){
    return View::make('users.reset_password');
});
.

フォームを表示するためにフォームがemail, new passwordなどを送信するために、

として定義されているルートのPOSTに登録されます。
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)
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top