【发布时间】:2020-01-27 09:00:22
【问题描述】:
在 laravel 中进行密码重置时,我还需要获取用户在密码中输入的密码并确认密码字段,我需要这个,因为我必须将其发布到另一个 api 以在那里更新密码.
您能告诉我如何访问它吗?
我已经检查了控制器的 Auth ResetPasswordcontroller.php,但我不知道如何拦截和获取纯文本密码,但仍然无法正常重置密码。
【问题讨论】:
在 laravel 中进行密码重置时,我还需要获取用户在密码中输入的密码并确认密码字段,我需要这个,因为我必须将其发布到另一个 api 以在那里更新密码.
您能告诉我如何访问它吗?
我已经检查了控制器的 Auth ResetPasswordcontroller.php,但我不知道如何拦截和获取纯文本密码,但仍然无法正常重置密码。
【问题讨论】:
您可以简单地从控制器中的 ResetsPasswords 特征覆盖 reset() 方法。
ResetPasswordController.php
class ResetPasswordController extends Controller
{
use ResetsPasswords;
// ...
public function reset(Request $request)
{
// the code in this section is copied from ResetsPasswords@reset
$request->validate($this->rules(), $this->validationErrorMessages());
// --- put your custom code here ------------
$plaintext_password = $request->password;
// --- end custom code ----------------------
// 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);
}
}
【讨论】: