File: D:/HostingSpaces/SBogers75/roost-interieurbouw.nl/app/Komma/Contact/ContactController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Contact;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Response;
use Komma\Mailers\ContactMailer;
use Komma\Page\PageService;
class ContactController extends Controller
{
protected $contactService;
protected $mailService;
protected $pageService;
/**
* ContactController constructor.
* @param ContactService $contactService
*/
public function __construct(ContactService $contactService, ContactMailer $mailService, PageService $pageService)
{
$this->mailService = $mailService;
$this->contactService = $contactService;
$this->pageService = $pageService;
}
public function contactFormSuccess()
{
$data = [];
$data = array_merge($data, $this->pageService->loadContent());
$data = array_merge($data, $this->pageService->loadImages());
$data['no_slider'] = true;
return \View::make('layouts.pages.thankYou')->with('data', (object)$data);
}
public function contactFormProcessNew(){
$inputs = \Input::all();
if(!isset($inputs['willie']) || $inputs['willie'] !== 'wonka'){
Log::warning('ContactController: No secret code found.');
return Response::json([
'status' => 422,
'errors' => [
'secretCode' => ['Oeps er gaat iets fout']
]
]);
}
if(!isset($inputs['honey']) || $inputs['honey'] !== '' ){
Log::warning('ContactController: Honeypot filled.');
return Response::json([
'status' => 422,
'errors' => [
'honey' => ['De ingevulde contactgegevens bevat overeenkomsten met een door een bot ingevulde data. Herlaad de pagina en vul de gegevens handmatig in.']
]
]);
}
//Validate the input
$validation = $this->contactService->validateContactForm($inputs);
//If The validation is not null, redirect back to the form with the errors.
if($validation !== null && $inputs['willie'] === 'wonka'){
Log::info('ContactController: Validation not successful.');
return Response::json([
'status' => 422,
'errors' => $validation
]);
}
$this->mailService->sendForm($inputs);
Log::info('ContactController: Mail send.');
return Response::json([
'status' => 200,
'data' => [
'redirectUrl' => route('contact.success')
],
]);
}
}