将recaptcha添加到默认的Laravel密码重置

问题描述 投票:0回答:1

我想要求我的Laravel 5.1应用程序的用户完成Google Recaptcha流程,但我无法弄清楚如何安全地修改发送重置密码链接的代码。

为我这样做的代码是继承的特征“ResetsPassword”中的“postEmail()”函数。这是我的整个PasswordController:

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Foundation\Auth\ResetsPasswords;

class PasswordController extends Controller {

use ResetsPasswords;

/**
 * Create a new password controller instance.
 *
 * @param  \Illuminate\Contracts\Auth\Guard  $auth
 * @param  \Illuminate\Contracts\Auth\PasswordBroker  $passwords
 * @return void
 */
public function __construct(Guard $auth, PasswordBroker $passwords)
{
    $this->auth = $auth;
    $this->passwords = $passwords;

    $this->middleware('guest');
}

}

如您所见,所有实际方法都在供应商文件中的“ResetsPasswords”特征中,因此我不想直接修改它。如何在PasswordsController中安全地修改继承特征中的“postEmail()”函数?

laravel laravel-5 laravel-5.1 recaptcha change-password
1个回答
2
投票

在你的ForgotPasswordController中添加以下方法:

protected function validateEmail(Request $request)
{
    $this->validate($request, [
        'email' => 'required|email',
        'g-recaptcha-response' => 'recaptcha',
    ]);
}

并按照我的reCAPTCHA实施指南:Laravel reCaptcha integration

© www.soinside.com 2019 - 2024. All rights reserved.