new updates
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreContactMessageRequest;
|
||||
use App\Mail\ContactFormSubmission;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use Klevze\ControlPanel\Facades\ActiveLanguage;
|
||||
@@ -32,14 +34,33 @@ class PageController extends Controller
|
||||
|
||||
public function about(): View
|
||||
{
|
||||
return $this->render('pages.about', 'About Us', 'about');
|
||||
$aboutPage = DB::table('contents')
|
||||
->where('content_id', 4)
|
||||
->exists()
|
||||
? app(CmsPage::class)->load(4, app()->getLocale())
|
||||
: null;
|
||||
|
||||
$seo = $this->pageSeo($aboutPage, 'About Us');
|
||||
|
||||
return $this->render('pages.about', $seo['title'], 'about', [
|
||||
'seo' => $seo,
|
||||
]);
|
||||
}
|
||||
|
||||
public function work(): View
|
||||
{
|
||||
$workPage = DB::table('contents')
|
||||
->where('content_id', 3)
|
||||
->exists()
|
||||
? app(CmsPage::class)->load(3, app()->getLocale())
|
||||
: null;
|
||||
|
||||
$seo = $this->pageSeo($workPage, 'Works');
|
||||
|
||||
$categoryMap = $this->projectCategoryMap();
|
||||
|
||||
return $this->render('pages.work', 'Works', 'work', [
|
||||
return $this->render('pages.work', $seo['title'], 'work', [
|
||||
'seo' => $seo,
|
||||
'artworks' => $this->portfolioProjects($categoryMap),
|
||||
'categories' => array_values($categoryMap),
|
||||
]);
|
||||
@@ -74,12 +95,34 @@ class PageController extends Controller
|
||||
|
||||
public function contact(): View
|
||||
{
|
||||
return $this->render('pages.contact', 'Contact Us', 'contact');
|
||||
session(['contact_form_started_at' => now()->timestamp]);
|
||||
|
||||
$contactPage = DB::table('contents')
|
||||
->where('content_id', 6)
|
||||
->exists()
|
||||
? app(CmsPage::class)->load(6, app()->getLocale())
|
||||
: null;
|
||||
|
||||
$seo = $this->pageSeo($contactPage, 'Contact Us');
|
||||
|
||||
return $this->render('pages.contact', $seo['title'], 'contact', [
|
||||
'seo' => $seo,
|
||||
]);
|
||||
}
|
||||
|
||||
public function terms(): View
|
||||
{
|
||||
return $this->render('pages.terms', 'Terms', 'terms');
|
||||
$termsPage = DB::table('contents')
|
||||
->where('content_id', 1)
|
||||
->exists()
|
||||
? app(CmsPage::class)->load(1, app()->getLocale())
|
||||
: null;
|
||||
|
||||
$seo = $this->pageSeo($termsPage, 'Terms');
|
||||
|
||||
return $this->render('pages.terms', $seo['title'], 'terms', [
|
||||
'seo' => $seo,
|
||||
]);
|
||||
}
|
||||
|
||||
public function thankyou(): View
|
||||
@@ -89,9 +132,15 @@ class PageController extends Controller
|
||||
|
||||
public function submitContact(StoreContactMessageRequest $request): RedirectResponse
|
||||
{
|
||||
Log::info('Website contact form submission', $request->validated());
|
||||
$contactDetails = $request->validated();
|
||||
|
||||
return redirect()->route('thankyou');
|
||||
Log::info('Website contact form submission', $contactDetails);
|
||||
|
||||
Mail::to('office@aritmija.si')->send(new ContactFormSubmission($contactDetails));
|
||||
|
||||
$request->session()->forget('contact_form_started_at');
|
||||
|
||||
return redirect()->route('thankyou', ['locale' => app()->getLocale()]);
|
||||
}
|
||||
|
||||
private function render(string $view, string $title, string $page, array $data = []): View
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class StoreContactMessageRequest extends FormRequest
|
||||
{
|
||||
private const MIN_SUBMIT_SECONDS = 3;
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
@@ -17,6 +21,52 @@ class StoreContactMessageRequest extends FormRequest
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'message' => ['required', 'string', 'max:2000'],
|
||||
'website' => ['nullable', 'string', 'max:0'],
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [function (Validator $validator): void {
|
||||
if ($this->submittedTooQuickly()) {
|
||||
$validator->errors()->add('form', 'Please wait a moment and try again.');
|
||||
}
|
||||
|
||||
if ($this->containsSpamLinks()) {
|
||||
$validator->errors()->add('message', 'Please remove promotional links and try again.');
|
||||
}
|
||||
|
||||
if ($this->nameContainsUrl()) {
|
||||
$validator->errors()->add('name', 'Please enter a valid name.');
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
private function submittedTooQuickly(): bool
|
||||
{
|
||||
$startedAt = (int) $this->session()->get('contact_form_started_at', 0);
|
||||
|
||||
if ($startedAt <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return now()->timestamp - $startedAt < self::MIN_SUBMIT_SECONDS;
|
||||
}
|
||||
|
||||
private function containsSpamLinks(): bool
|
||||
{
|
||||
return preg_match_all('/https?:\/\/|www\./i', (string) $this->input('message', '')) > 1;
|
||||
}
|
||||
|
||||
private function nameContainsUrl(): bool
|
||||
{
|
||||
return Str::contains(Str::lower((string) $this->input('name', '')), ['http://', 'https://', 'www.']);
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'website.max' => 'Please leave this field empty.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user