php - ResetPasswordController 如何使用密码重置表 Laravel
问题描述
内置密码重置控制器 Auth\Reset Password Controller 具有重置功能
public function reset(Request $request)
{
$request->validate($this->rules(), $this->validationErrorMessages());
// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$response = $this->broker()->reset(
$this->credentials($request), function ($user, $password) {
$this->resetPassword($user, $password);
}
);
// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
return $response == Password::PASSWORD_RESET
? $this->sendResetResponse($request, $response)
: $this->sendResetFailedResponse($request, $response);
}
好吧,这里我们正在处理用户及其传入的数据。但是,我不明白 password_resets 表(内置)的工作在哪里?毕竟,在密码恢复后,条目会在那里添加/删除。我认为(可能不正确)这是在 broker() 方法中实现的,但我在特征、接口和其他类的层次结构中找不到它。
解决方案
结帐/vendor/laravel/framework/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php
这是实现 的默认类,TokenRepositoryInterface
并由/vendor/laravel/framework/src/Illuminate/Auth/Passwords/PasswordBroker.php
.
在此类中,您可以找到处理密码重置的所有实际功能,包括您提到的表操作。例如,您会发现一种方法是:
/**
* Create a new token record.
*
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
* @return string
*/
public function create(CanResetPasswordContract $user)
{
$email = $user->getEmailForPasswordReset();
$this->deleteExisting($user);
// We will create a new, random token for the user so that we can e-mail them
// a safe link to the password reset form. Then we will insert a record in
// the database so that we can verify the token within the actual reset.
$token = $this->createNewToken();
$this->getTable()->insert($this->getPayload($email, $token));
return $token;
}
推荐阅读
- javascript - 解构数组中的嵌套对象
- python - 在过渡到 Ubuntu 时,如何使用 chromedriver Windows >>> 修复可执行错误?
- visual-studio-2013 - 无法安装包“Microsoft.Extensions.Logging 2.1.1”
- elasticsearch - Elasticsearch 术语聚合 - 用于对象的动态键
- javascript - 如何转换为字符串以插入到sql中
- javascript - 为什么我的 for 循环卡在第二个选项上?
- ruby-on-rails - 有什么用!在铁轨上
- postgresql - 使用 psycopg2 将 csv 上传到 postgresql
- c# - Xamarin.forms One Signal PromptLocation 方法
- c - 将 2 字节变量分配给 3 字节寄存器?