密码提醒的 Laravel 令牌总是不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24400323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Token For Password Reminder Always Mismatch
提问by randytan
Hi there i have some strange problem for password reminder system. The return for this function is always password token mismatch.
嗨,我有一些密码提醒系统的奇怪问题。此函数的返回始终是密码令牌不匹配。
here is the remember controller
这是记住控制器
<?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.');
}
}
}
and the Routes.php
和Routes.php
Route::get('reset', function() {
return View::make('resetacc');
});
Route::get('password/reset/{token}', array(
'uses' => 'RemindersController@getReset',
'as' => 'resetpass'
));
the token stored in database is equally the same with the one given to user.
存储在数据库中的令牌与提供给用户的令牌相同。
i have the laravel version 4.1 then updated to 4.2.5
我有 Laravel 版本 4.1 然后更新到 4.2.5
is it because of the update process?
是因为更新过程吗?
thanks
谢谢
采纳答案by Luke
You need add something like {{ Form::hidden('token', $token) }}
into your reset form.
您需要{{ Form::hidden('token', $token) }}
在重置表单中添加类似的内容。
回答by PiTheNumber
For the sake of completeness: This error could also mean that the token is simply expired.
为完整起见:此错误也可能意味着令牌已过期。
You can set reminder.expire
in config/auth.php
.
您可以reminder.expire
在config/auth.php
.
Default is 60 minutes.
默认为 60 分钟。
https://laravel.com/docs/5.1/authentication#after-resetting-passwords
https://laravel.com/docs/5.1/authentication#after-resetting-passwords
回答by KalC
If you have subdomainrouting in your application, you will have to modify your getReset method to include the subdomain parameter in the function's parameter list.
如果您的应用程序中有子域路由,则必须修改 getReset 方法以在函数的参数列表中包含子域参数。
public function getReset($club="",$token = null)
{
if (is_null($token)) {
throw new NotFoundHttpException;
}
return view('auth.reset')->with('token', $token);
}