在laravel中重置密码时,我还需要获取用户在密码上输入的密码并确认密码字段,我需要这样做,因为我必须将其发布到另一个api上,以在那里更新密码
您能告诉我如何使用它吗?
我已经检查了控制器的Auth ResetPasswordcontroller.php,但是我无法弄清楚如何截取并获取纯文本密码,但是仍然无法进行正常的密码重置。
答案 0 :(得分:1)
您可以简单地从控制器内的 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);
}
}