这是我的config / auth.php
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
'customers' => [
'provider' => 'customers',
'table' => 'customer_password_resets',
'expire' => 120,
],
'admin' => [
'provider' => 'admins',
'table' => 'admin_password_resets',
'expire' => 60,
],
],
尝试重设客户密码时,出现错误“此令牌无效”。
这是我的ResetsPassword.php-> reset()
public function reset(Request $request)
{
$this->validate($request, $this->rules(), $this->validationErrorMessages());
$response = $this->broker()->reset(
$this->credentials($request), function ($user, $password) {
$this->resetPassword($user, $password);
}
);
return $response == Password::PASSWORD_RESET
? $this->sendResetResponse($response)
: $this->sendResetFailedResponse($request, $response);
}
答案 0 :(得分:1)
必须先生成密码重置令牌,然后才能发布到password.update
路由。通常,当用户在向其发送密码重置链接之前在表单中输入其电子邮件地址时,就会发生这种情况。
对于自定义实现,您可能需要手动生成令牌。
use Illuminate\Auth\Passwords\PasswordBroker;
// insert a token record into the password reset table
$token = app(PasswordBroker::class)->createToken($customer);
编辑:令牌从代理返回的值是未加密的值,同时,令牌将其作为哈希值存储在数据库中。与CSRF reset()
不同,请确保将 unhashed 令牌值作为参数token
提交给_token
方法,且不带下划线。
此外,您的Customer
模型必须扩展Authenticatable
。
class Customer extends Authenticatable
{
// ...
}