user shop sites
This commit is contained in:
parent
22a2b4710a
commit
dc857e88d5
37 changed files with 2044 additions and 869 deletions
106
app/Http/Controllers/Web/ContactController.php
Executable file
106
app/Http/Controllers/Web/ContactController.php
Executable file
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailContact;
|
||||
use GuzzleHttp\Client;
|
||||
use Input;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Util;
|
||||
use Validator;
|
||||
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
private $GOOGLE_ReCAPTCHA_KEY = "6LeeZosUAAAAAG907fMMqO4BFgsiR4ANDodd8FlU";
|
||||
private $GOOGLE_ReCAPTCHA_SECRET = "6LeeZosUAAAAADIy2fyR4RG3EuM-Zdz7Pa2Qmb1J";
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data = [
|
||||
'GOOGLE_ReCAPTCHA_KEY' => $this->GOOGLE_ReCAPTCHA_KEY,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.kontakt', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
$rules = array(
|
||||
'first_name'=>'required',
|
||||
'last_name'=>'required',
|
||||
'email'=>'required|email',
|
||||
'message'=>'required',
|
||||
'g-recaptcha-response'=>'required|recaptcha',
|
||||
'accepted_data_protection' => 'required',
|
||||
);
|
||||
|
||||
Validator::extend('recaptcha', function($attribute, $value, $parameters, $validator) {
|
||||
return $this->reCaptcha_validate($attribute, $value, $parameters, $validator);
|
||||
});
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withErrors($validator)->withInput(Input::all());
|
||||
}else{
|
||||
|
||||
$contact = [];
|
||||
$contact['first_name'] = Input::get('first_name');
|
||||
$contact['last_name'] = Input::get('last_name');
|
||||
$contact['email'] = Input::get('email');
|
||||
$contact['phone'] = Input::get('phone');
|
||||
$contact['subject'] = Input::get('subject');
|
||||
$contact['message'] = Input::get('message');
|
||||
|
||||
if($user_shop){
|
||||
Mail::to($contact['email'])->bcc([$user_shop->user->email, 'k.adametz@kagado.de'])->send(new MailContact($contact));
|
||||
}else{
|
||||
Mail::to($contact['email'])->bcc('k.adametz@kagado.de')->send(new MailContact($contact));
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.contact-final', $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function reCaptcha_validate($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
|
||||
$client = new Client();
|
||||
|
||||
$response = $client->post(
|
||||
'https://www.google.com/recaptcha/api/siteverify',
|
||||
['form_params' =>
|
||||
[
|
||||
'secret' => $this->GOOGLE_ReCAPTCHA_SECRET,
|
||||
'response' => $value
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$body = json_decode((string)$response->getBody());
|
||||
return $body->success;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue