Skip to content

Commit 370d429

Browse files
committed
feat: added contact form. display user country in google map.+ tests
1 parent aa39aa3 commit 370d429

35 files changed

+1590
-93
lines changed

.phpstorm.meta.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'hash' => \Illuminate\Hashing\HashManager::class,
184184
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
185185
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
186+
'location' => \Stevebauman\Location\Location::class,
186187
'log' => \Illuminate\Log\LogManager::class,
187188
'mail.manager' => \Illuminate\Mail\MailManager::class,
188189
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -384,6 +385,7 @@
384385
'hash' => \Illuminate\Hashing\HashManager::class,
385386
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
386387
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
388+
'location' => \Stevebauman\Location\Location::class,
387389
'log' => \Illuminate\Log\LogManager::class,
388390
'mail.manager' => \Illuminate\Mail\MailManager::class,
389391
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -585,6 +587,7 @@
585587
'hash' => \Illuminate\Hashing\HashManager::class,
586588
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
587589
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
590+
'location' => \Stevebauman\Location\Location::class,
588591
'log' => \Illuminate\Log\LogManager::class,
589592
'mail.manager' => \Illuminate\Mail\MailManager::class,
590593
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -786,6 +789,7 @@
786789
'hash' => \Illuminate\Hashing\HashManager::class,
787790
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
788791
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
792+
'location' => \Stevebauman\Location\Location::class,
789793
'log' => \Illuminate\Log\LogManager::class,
790794
'mail.manager' => \Illuminate\Mail\MailManager::class,
791795
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -987,6 +991,7 @@
987991
'hash' => \Illuminate\Hashing\HashManager::class,
988992
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
989993
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
994+
'location' => \Stevebauman\Location\Location::class,
990995
'log' => \Illuminate\Log\LogManager::class,
991996
'mail.manager' => \Illuminate\Mail\MailManager::class,
992997
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -1188,6 +1193,7 @@
11881193
'hash' => \Illuminate\Hashing\HashManager::class,
11891194
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
11901195
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
1196+
'location' => \Stevebauman\Location\Location::class,
11911197
'log' => \Illuminate\Log\LogManager::class,
11921198
'mail.manager' => \Illuminate\Mail\MailManager::class,
11931199
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -1389,6 +1395,7 @@
13891395
'hash' => \Illuminate\Hashing\HashManager::class,
13901396
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
13911397
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
1398+
'location' => \Stevebauman\Location\Location::class,
13921399
'log' => \Illuminate\Log\LogManager::class,
13931400
'mail.manager' => \Illuminate\Mail\MailManager::class,
13941401
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -1590,6 +1597,7 @@
15901597
'hash' => \Illuminate\Hashing\HashManager::class,
15911598
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
15921599
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
1600+
'location' => \Stevebauman\Location\Location::class,
15931601
'log' => \Illuminate\Log\LogManager::class,
15941602
'mail.manager' => \Illuminate\Mail\MailManager::class,
15951603
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -1791,6 +1799,7 @@
17911799
'hash' => \Illuminate\Hashing\HashManager::class,
17921800
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
17931801
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
1802+
'location' => \Stevebauman\Location\Location::class,
17941803
'log' => \Illuminate\Log\LogManager::class,
17951804
'mail.manager' => \Illuminate\Mail\MailManager::class,
17961805
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -1992,6 +2001,7 @@
19922001
'hash' => \Illuminate\Hashing\HashManager::class,
19932002
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
19942003
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
2004+
'location' => \Stevebauman\Location\Location::class,
19952005
'log' => \Illuminate\Log\LogManager::class,
19962006
'mail.manager' => \Illuminate\Mail\MailManager::class,
19972007
'mailer' => \Illuminate\Mail\Mailer::class,
@@ -2193,6 +2203,7 @@
21932203
'hash' => \Illuminate\Hashing\HashManager::class,
21942204
'hash.driver' => \Illuminate\Hashing\BcryptHasher::class,
21952205
'inertia.testing.view-finder' => \Illuminate\View\FileViewFinder::class,
2206+
'location' => \Stevebauman\Location\Location::class,
21962207
'log' => \Illuminate\Log\LogManager::class,
21972208
'mail.manager' => \Illuminate\Mail\MailManager::class,
21982209
'mailer' => \Illuminate\Mail\Mailer::class,

_ide_helper.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19419,6 +19419,52 @@ public static function group($groupName, $properties)
1941919419

1942019420
}
1942119421

19422+
}
19423+
19424+
namespace Stevebauman\Location\Facades {
19425+
/**
19426+
*
19427+
*
19428+
* @see \Stevebauman\Location\Location
19429+
*/
19430+
class Location {
19431+
/**
19432+
* Set the current driver to use.
19433+
*
19434+
* @param \Stevebauman\Location\Drivers\Driver $driver
19435+
* @static
19436+
*/
19437+
public static function setDriver($driver)
19438+
{
19439+
/** @var \Stevebauman\Location\Location $instance */
19440+
return $instance->setDriver($driver);
19441+
}
19442+
/**
19443+
* Set the default location driver to use.
19444+
*
19445+
* @throws DriverDoesNotExistException
19446+
* @static
19447+
*/
19448+
public static function setDefaultDriver()
19449+
{
19450+
/** @var \Stevebauman\Location\Location $instance */
19451+
return $instance->setDefaultDriver();
19452+
}
19453+
/**
19454+
* Attempt to retrieve the location of the user.
19455+
*
19456+
* @param string|null $ip
19457+
* @return \Stevebauman\Location\Position|bool
19458+
* @static
19459+
*/
19460+
public static function get($ip = null)
19461+
{
19462+
/** @var \Stevebauman\Location\Location $instance */
19463+
return $instance->get($ip);
19464+
}
19465+
19466+
}
19467+
1942219468
}
1942319469

1942419470
namespace Illuminate\Http {
@@ -23411,6 +23457,7 @@ class Debugbar extends \Barryvdh\Debugbar\Facades\Debugbar {}
2341123457
class Action extends \Lorisleiva\Actions\Facades\Actions {}
2341223458
class Lody extends \Lorisleiva\Lody\Lody {}
2341323459
class Flare extends \Spatie\LaravelIgnition\Facades\Flare {}
23460+
class Location extends \Stevebauman\Location\Facades\Location {}
2341423461

2341523462
}
2341623463

_ide_helper_actions.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
class Dashboard
88
{
99
}
10+
namespace App\Actions\Admin\Settings;
11+
12+
/**
13+
*/
14+
class Configurations
15+
{
16+
}
17+
/**
18+
*/
19+
class ResetSystem
20+
{
21+
}
1022
namespace App\Actions\Auth;
1123

1224
/**
@@ -26,6 +38,11 @@ class Register
2638
}
2739
namespace App\Actions\Auth\Pages;
2840

41+
/**
42+
*/
43+
class ForgotPassword
44+
{
45+
}
2946
/**
3047
*/
3148
class Login
@@ -36,6 +53,11 @@ class Login
3653
class Register
3754
{
3855
}
56+
/**
57+
*/
58+
class ResetPassword
59+
{
60+
}
3961
namespace App\Actions\Frontend;
4062

4163
/**
@@ -53,6 +75,11 @@ class Contact
5375
class Home
5476
{
5577
}
78+
/**
79+
*/
80+
class PolicyPages
81+
{
82+
}
5683
namespace App\Actions\User;
5784

5885
/**

app/Actions/Frontend/Contact.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,62 @@
22

33
namespace App\Actions\Frontend;
44

5+
use App\Events\ContactFormWasFilled;
6+
use App\Models\ContactMessage;
7+
use App\Traits\CustomControllerResponsesTrait;
58
use App\Traits\ThemesTrait;
9+
use Illuminate\Http\Request;
610
use Lorisleiva\Actions\Concerns\AsAction;
11+
use Stevebauman\Location\Facades\Location;
712

813
class Contact
914
{
1015
use AsAction;
1116
use ThemesTrait;
17+
use CustomControllerResponsesTrait;
1218

13-
public function asController()
19+
public function asController(Request $request)
1420
{
15-
return $this->generatePage('contact', 'Contact');
21+
if($request->isMethod('get')) {
22+
$data = [
23+
'country' => 'United Kingdom',
24+
];
25+
26+
if ($position = Location::get()) {
27+
$data = [
28+
'country' => $position->countryName,
29+
];
30+
}
31+
32+
return $this->generatePage('contact', 'Contact', $data);
33+
}
34+
35+
$request->validate([
36+
'name' => 'required|string|max:255',
37+
'email' => 'nullable|email|max:255',
38+
'phone' => 'nullable|string|max:20|min:10|required_without:email',
39+
'subject' => 'required|string|max:255',
40+
'body' => 'required|string|max:10000',
41+
], [
42+
'name.required' => 'Please provide your name(s)',
43+
]);
44+
45+
$resp = ContactMessage::create([
46+
'user_id' => doe() ? doe()->id : null,
47+
'name' => $request->name,
48+
'email' => $request->email,
49+
'phone' => $request->phone,
50+
'subject' => $request->subject,
51+
'body' => $request->body,
52+
'site_domain' => sanitizeDomainUrl(),
53+
'ip_address' => $request->ip(),
54+
]);
55+
56+
event(new ContactFormWasFilled($resp));
57+
58+
return $request->wantsJson()
59+
? $this->respJuicer($resp, "We have received your message. We shall get in touch soon.")
60+
: back()->with('success', "We have received your message. We shall get in touch soon.");
61+
1662
}
1763
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Models\ContactMessage;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Broadcasting\InteractsWithSockets;
8+
use Illuminate\Broadcasting\PresenceChannel;
9+
use Illuminate\Broadcasting\PrivateChannel;
10+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
11+
use Illuminate\Foundation\Events\Dispatchable;
12+
use Illuminate\Queue\SerializesModels;
13+
14+
class ContactFormWasFilled
15+
{
16+
use Dispatchable, InteractsWithSockets, SerializesModels;
17+
18+
public $contactMessage;
19+
20+
/**
21+
* Create a new event instance.
22+
*/
23+
public function __construct(ContactMessage $contactMessage)
24+
{
25+
$this->contactMessage = $contactMessage;
26+
}
27+
28+
/**
29+
* Get the channels the event should broadcast on.
30+
*
31+
* @return array<int, \Illuminate\Broadcasting\Channel>
32+
*/
33+
public function broadcastOn(): array
34+
{
35+
return [
36+
new PrivateChannel('channel-name'),
37+
];
38+
}
39+
}

app/Jobs/SendLoginAlertEmail.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use App\Notifications\NotifyUserOfLogin;
6+
use Illuminate\Bus\Queueable;
7+
use Illuminate\Contracts\Queue\ShouldBeUnique;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Foundation\Bus\Dispatchable;
10+
use Illuminate\Queue\InteractsWithQueue;
11+
use Illuminate\Queue\SerializesModels;
12+
use Illuminate\Support\Facades\Log;
13+
14+
class SendLoginAlertEmail implements ShouldQueue
15+
{
16+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
17+
18+
public $user, $requestData;
19+
20+
public $tries = 3;
21+
public $timeout = 120;
22+
23+
/**
24+
* Create a new job instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct($user, array $requestData)
29+
{
30+
$this->user = $user;
31+
$this->requestData = $requestData;
32+
}
33+
34+
/**
35+
* Execute the job.
36+
*
37+
* @return void
38+
*/
39+
public function handle()
40+
{
41+
// send notification
42+
if($this->user->created_at >= now()->subMinutes(5)) {
43+
// user recently added or not active. No need to send an alert
44+
45+
// log the activity
46+
if($this->user->isSudo)
47+
Log::channel('sudo-logins')->info('New user login. Email: ' . $this->user->email);
48+
else
49+
Log::channel('user-logins')->info('New user login. Email: ' . $this->user->email);
50+
51+
} else {
52+
$this->user->notify(new NotifyUserOfLogin($this->requestData));
53+
}
54+
}
55+
}

app/Library/events.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3+
use App\Events\ContactFormWasFilled;
34
use App\Events\CRUDErrorOccurred;
45
use App\Events\UserLoggedIn;
56
use App\Events\UserWasCreated;
7+
use App\Listeners\ContactFormHasBeenFilled;
68
use App\Listeners\CRUDErrorHasOccurred;
79
use App\Listeners\UserHasBeenCreated;
810
use App\Listeners\UserHasLoggedIn;
@@ -18,7 +20,11 @@
1820

1921
UserWasCreated::class => [
2022
UserHasBeenCreated::class,
21-
]
23+
],
24+
25+
ContactFormWasFilled::class => [
26+
ContactFormHasBeenFilled::class,
27+
],
2228

2329

2430
];

0 commit comments

Comments
 (0)