我想要求我的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()”函数?
在你的ForgotPasswordController
中添加以下方法:
protected function validateEmail(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'g-recaptcha-response' => 'recaptcha',
]);
}
并按照我的reCAPTCHA实施指南:Laravel reCaptcha integration