Switch custom Guzzle integration for Laravel's HTTP facade

Commit also adds config options to the example file.
This commit is contained in:
Miguel Nogueira 2020-05-02 20:18:56 +01:00
parent 623200914d
commit 7cf056f57e
3 changed files with 1728 additions and 1726 deletions

View File

@ -13,6 +13,11 @@ DB_DATABASE=laravel
DB_USERNAME=root DB_USERNAME=root
DB_PASSWORD= DB_PASSWORD=
RECAPTCHA_SITE_KEY=
RECAPTCHA_PRIVATE_KEY=
RECAPTCHA_VERIFY_URL="https://www.google.com/recaptcha/api/siteverify"
# WARNING: Your contact form will be useless if you change this value. Only change this URL if Google updates it.
BROADCAST_DRIVER=log BROADCAST_DRIVER=log
CACHE_DRIVER=file CACHE_DRIVER=file
QUEUE_CONNECTION=sync QUEUE_CONNECTION=sync

View File

@ -4,15 +4,13 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use GuzzleHttp; use GuzzleHttp;
use Illuminate\Support\Facades\Http;
class ContactController extends Controller class ContactController extends Controller
{ {
public function create(Request $request) public function create(Request $request)
{ {
// TODO: use service provider instead
$client = new GuzzleHttp\Client();
$name = $request->name; $name = $request->name;
$email = $request->email; $email = $request->email;
$subject = $request->subject; $subject = $request->subject;
@ -20,13 +18,12 @@ class ContactController extends Controller
$challenge = $request->input('captcha'); $challenge = $request->input('captcha');
$verifyrequest = $client->request('POST', config('recaptcha.verify.apiurl'), [ $verifyrequest = Http::asForm()->post(config('recaptcha.verify.apiurl'), [
'form_params' => [ 'secret' => config('recaptcha.keys.secret'),
'secret' => config('recaptcha.keys.secret'), 'response' => $challenge,
'response' => $challenge, 'remoteip' => $_SERVER['REMOTE_ADDR']
'remoteip' => $_SERVER['REMOTE_ADDR']
]
]); ]);
$response = json_decode($verifyrequest->getBody(), true); $response = json_decode($verifyrequest->getBody(), true);
if (!$response['success']) if (!$response['success'])

3434
package-lock.json generated

File diff suppressed because it is too large Load Diff