2020-04-27 06:28:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-10-21 00:29:50 +00:00
|
|
|
use GuzzleHttp;
|
|
|
|
use App\Notifications\NewContact;
|
2020-10-21 00:01:41 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2020-07-16 20:21:28 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
use App\User;
|
|
|
|
|
2020-04-27 06:28:00 +00:00
|
|
|
class ContactController extends Controller
|
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
protected $users;
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
public function __construct(User $users)
|
|
|
|
{
|
|
|
|
$this->users = $users;
|
|
|
|
}
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-04-27 06:28:00 +00:00
|
|
|
public function create(Request $request)
|
|
|
|
{
|
|
|
|
$name = $request->name;
|
|
|
|
$email = $request->email;
|
|
|
|
$subject = $request->subject;
|
|
|
|
$msg = $request->msg;
|
|
|
|
|
|
|
|
$challenge = $request->input('captcha');
|
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
// TODO: now: add middleware for this verification, move to invisible captcha
|
2020-05-02 19:18:56 +00:00
|
|
|
$verifyrequest = Http::asForm()->post(config('recaptcha.verify.apiurl'), [
|
|
|
|
'secret' => config('recaptcha.keys.secret'),
|
|
|
|
'response' => $challenge,
|
2020-10-21 00:29:50 +00:00
|
|
|
'remoteip' => $request->ip()
|
2020-04-27 06:28:00 +00:00
|
|
|
]);
|
2020-05-02 19:18:56 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-04-27 06:28:00 +00:00
|
|
|
$response = json_decode($verifyrequest->getBody(), true);
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
if (!$response['success'])
|
|
|
|
{
|
2020-04-27 06:28:00 +00:00
|
|
|
$request->session()->flash('error', 'Beep beep boop... Robot? Submission failed.');
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
|
|
|
foreach(User::all() as $user)
|
|
|
|
{
|
|
|
|
if ($user->hasRole('admin'))
|
|
|
|
{
|
|
|
|
$user->notify(new NewContact(collect([
|
|
|
|
'message' => $msg,
|
|
|
|
'ip' => $request->ip(),
|
|
|
|
'email' => $email
|
|
|
|
])));
|
|
|
|
}
|
2020-07-16 20:21:28 +00:00
|
|
|
}
|
2020-04-27 06:28:00 +00:00
|
|
|
|
|
|
|
$request->session()->flash('success', 'Message sent successfully! We usually respond within 48 hours.');
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|