用于密码提示的Laravel令牌始终不匹配

时间:2014-06-25 04:42:52

标签: php laravel token remember-me

您好我的密码提醒系统有一些奇怪的问题。此函数的返回始终是密码令牌不匹配。

这是记住控制器

  <?php

 class RemindersController extends Controller {

/**
 * Display the password reminder view.
 *
 * @return Response
 */
public function getRemind()
{
    return View::make('resetacc');
}

/**
 * Handle a POST request to remind a user of their password.
 *
 * @return Response
 */
public function postRemind()
{
    switch ($response = Password::remind(Input::only('email')))
    {
        case Password::INVALID_USER:
            return Redirect::back()->with('message', Lang::get($response));

        case Password::REMINDER_SENT:
            return Redirect::back()->with('message', Lang::get($response));
    }
}

/**
 * Display the password reset view for the given token.
 *
 * @param  string  $token
 * @return Response
 */
public function getReset($token = null)
{
    if (is_null($token)) App::abort(404);

    return View::make('resetpass')->with('token', $token);
}

/**
 * Handle a POST request to reset a user's password.
 *
 * @return Response
 */
public function postReset()
{
    $credentials = Input::only(
        'email', 'password', 'password_confirmation', 'token'
    );

    $response = Password::reset($credentials, function($user, $password)
    {
        $user->password = Hash::make($password);

        $user->save();
    });

    switch ($response)
    {
        case Password::INVALID_PASSWORD:
        case Password::INVALID_TOKEN:
            return Redirect::to('/reset')->with('message', Lang::get($response));
        case Password::INVALID_USER:
            return Redirect::back()->with('message', Lang::get($response));
        case Password::PASSWORD_RESET:
            return Redirect::to('/auth')->with('message', 'Password Reset anda berhasil, silahkan login.');
    }
}

}

Routes.php

Route::get('reset', function() {
    return View::make('resetacc');
});

Route::get('password/reset/{token}', array(
    'uses' => 'RemindersController@getReset',
    'as' => 'resetpass'
));

存储在数据库中的令牌与提供给用户的令牌同样相同。

我有laravel版本4.1然后更新到4.2.5

是因为更新过程吗?

感谢

3 个答案:

答案 0 :(得分:2)

您需要在重置表单中添加{{ Form::hidden('token', $token) }}之类的内容。

答案 1 :(得分:2)

如果您的应用程序中有子域路由,则必须修改getReset方法,以将subdomain参数包含在函数的参数列表中。

    public function getReset($club="",$token = null)
    {
        if (is_null($token)) {
            throw new NotFoundHttpException;
        }

        return view('auth.reset')->with('token', $token);
    }

答案 2 :(得分:2)

为了完整起见:此错误也可能意味着令牌已过期。

您可以在reminder.expire中设置config/auth.php

默认为60分钟。

https://laravel.com/docs/5.1/authentication#after-resetting-passwords