【问题标题】:Laravel Token For Password Reminder Always Mismatch用于密码提醒的 Laravel 令牌总是不匹配
【发布时间】:2014-08-15 12:34:15
【问题描述】:

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

这是记忆控制器

  <?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

是因为更新过程吗?

谢谢

【问题讨论】:

    标签: php laravel token remember-me


    【解决方案1】:

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

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

    默认为 60 分钟。

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

    【讨论】:

    • 这是我的情况...遗憾的是错误不明确。必须说“令牌已过期”或类似的东西...
    【解决方案2】:

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

        public function getReset($club="",$token = null)
        {
            if (is_null($token)) {
                throw new NotFoundHttpException;
            }
    
            return view('auth.reset')->with('token', $token);
        }
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-18
        • 2018-05-24
        • 2016-10-24
        • 2020-07-08
        • 2016-12-10
        • 2016-09-20
        • 2020-01-20
        • 2017-05-23
        相关资源
        最近更新 更多