Laravel получает простой текстовый пароль, когда пользователь вводит форму сброса пароля - PullRequest
0 голосов
/ 27 сентября 2019

При выполнении сброса пароля в laravel у меня также есть необходимость получить пароль, который пользователь вводит в пароль, и подтвердить поля пароля, мне это нужно, потому что я должен опубликовать его в другом API, чтобы обновить там пароль и там.

Подскажите, пожалуйста, как я могу получить к нему доступ.

Я проверил Auth ResetPasswordcontroller.php контроллера, но не могу понять, как перехватить и получить пароль в виде простого текста, но все жеразрешить нормальный сброс пароля.

Ответы [ 2 ]

1 голос
/ 27 сентября 2019

Вы можете просто переопределить метод reset() из черты ResetsPasswords внутри контроллера.

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);
    }    
}
0 голосов
/ 27 сентября 2019

Вы можете использовать laravel, встроенный в проверку подтверждено

У проверяемого поля должно быть соответствующее поле foo_confirmation.Например, если проверяемое поле имеет значение password, соответствующее поле password_confirmation должно присутствовать на входе.

Итак, вам нужно <input type="password" name="password"> и <input type="password" name = "password_confirmation"> и для контроллера:

// controller for your change password route
public function changePassword(Request $request)
{
    $request->validate([
        'password' => 'required|string|confirmed',
    ]);

    // Your change password code
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...