将Recaptcha添加到默认的Laravel密码重置 [英] Add recaptcha to default Laravel Password Reset

查看:98
本文介绍了将Recaptcha添加到默认的Laravel密码重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要求Laravel 5.1应用程序的用户已经完成Google Recaptcha流程,但是我不知道如何安全地修改发送重置密码链接的代码.

I want to require the users of my Laravel 5.1 application to have finished a Google Recaptcha process, but I can't figure out how to safely modify the code that sends the reset password link.

为我执行此操作的代码是继承的特征"ResetsPassword"中的"postEmail()"函数.这是我的整个PasswordController:

The code that does this for me is the "postEmail()" function in the inherited trait "ResetsPassword". This is my entire 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()"函数?

As you can see, all the real methods are in the "ResetsPasswords" trait which is in a vendor file so I don't want to modify it directly. How do I modify the "postEmail()" function in the inherited trait safely in my PasswordsController?

推荐答案

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

In your ForgotPasswordController add this method:

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

并在此处遵循我的reCAPTCHA实施指南: Laravel reCaptcha集成

And follow my reCAPTCHA implementation guide here: Laravel reCaptcha integration

这篇关于将Recaptcha添加到默认的Laravel密码重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆