Skip to content

Commit 05611dc

Browse files
committed
Integrate Google reCAPTCHA v3 and refactor profile
Added josiasmontag/laravel-recaptchav3 package and integrated Google reCAPTCHA v3 into the registration form for enhanced security. Updated environment variable names for reCAPTCHA configuration. Refactored the profile page to use the ProfileMain Livewire component, simplifying the view and improving maintainability. Minor UI and code improvements were also made.
1 parent d5a284c commit 05611dc

File tree

11 files changed

+82
-85
lines changed

11 files changed

+82
-85
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ TINYMCE_API=
7474
COOKIEBOT_ID=
7575

7676
# Google reCAPTCHA v3
77-
RECAPTCHA_SITE_KEY=your_site_key_here
78-
RECAPTCHA_SECRET_KEY=your_secret_key_here
77+
RECAPTCHAV3_SITEKEY=sitekey
78+
RECAPTCHAV3_SECRET=secret

app/Livewire/Auth/Register.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function register(): void
3030
'name' => ['required', 'string', 'max:255'],
3131
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
3232
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
33+
'g-recaptcha-response' => 'required|recaptchav3:register,0.5'
3334
]);
3435

3536
$validated['password'] = Hash::make($validated['password']);

app/Livewire/ProfileMain.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
namespace App\Livewire;
44

55
use Livewire\Component;
6+
use Illuminate\Support\Facades\Auth;
7+
use App\Models\User;
68

79
class ProfileMain extends Component
810
{
911
public $name;
1012
public $email;
13+
public User $user;
1114

1215
public function mount()
1316
{
1417
$user = auth()->user();
15-
$this->name = $user->name;
18+
$this->user = Auth::user();
1619
$this->email = $user->email;
1720
}
1821

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "MIT",
1111
"require": {
1212
"php": "^8.2",
13+
"josiasmontag/laravel-recaptchav3": "^1.0",
1314
"laravel/framework": "^12.0",
1415
"laravel/nightwatch": "^1.13",
1516
"laravel/tinker": "^2.10.1",

composer.lock

Lines changed: 67 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/components/layouts/main.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
data-blockingmode="{{ config('services.cookiebot.blocking_mode') }}"
2828
type="text/javascript"></script>
2929

30+
<!-- Google ReCaptcha V3 -->
31+
{!! RecaptchaV3::initJs() !!}
3032

3133
<!-- Styles -->
3234
@livewireStyles

resources/views/livewire/auth/register.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<x-auth-session-status class="text-center" :status="session('status')" />
66

77
<form method="POST" wire:submit="register" class="flex flex-col gap-6">
8+
{!! RecaptchaV3::field('register') !!}
89
<!-- Name -->
910
<flux:input
1011
wire:model="name"

resources/views/livewire/avatar-uploader.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
<form wire:submit="save">
33

4-
54
<flux:file-upload wire:model="photo">
65

76
<div

resources/views/livewire/profile-main.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
7878
Save Changes
7979
</button>
80+
<flux:button variant="primary" color="amber" wire:click="save">Save Changes</flux:button>
8081
</div>
8182
</form>
8283

resources/views/profile/index.blade.php

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -50,86 +50,8 @@
5050

5151
</div>
5252

53-
54-
<form wire:submit.prevent="save">
55-
56-
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
57-
<!-- Full Name -->
58-
<div class="space-y-2">
59-
<label for="name" class="block text-sm font-medium leading-none text-slate-200">Name</label>
60-
<input id="name" value="{{ $user->name }}" class="flex h-10 w-full rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-base text-slate-100 ring-offset-slate-950 placeholder:text-slate-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm" readonly />
61-
@error('name') <p class="text-red-500 text-sm">{{ $message }}</p> @enderror
62-
</div>
63-
64-
<!-- Email -->
65-
<div class="space-y-2">
66-
<label for="email" class="block text-sm font-medium leading-none text-slate-200">Email</label>
67-
<div class="relative">
68-
<input id="email" type="email" value="{{ $user->email }}" class="flex h-10 w-full rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-base text-slate-100 ring-offset-slate-950 placeholder:text-slate-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm" readonly />
69-
@error('email') <p class="text-red-500 text-sm">{{ $message }}</p> @enderror
70-
<div class="absolute right-3 top-1/2 -translate-y-1/2 flex items-center gap-2">
71-
@if ($user->email_verified_at)
72-
<span class="text-green-500 text-sm flex items-center gap-1">
73-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
74-
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
75-
</svg>
76-
Verified
77-
</span>
78-
@else
79-
<span class="text-yellow-500 text-sm flex items-center gap-1">
80-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
81-
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" />
82-
</svg>
83-
Not Verified
84-
</span>
85-
<a href="{{ route('verification.notice') }}" class="text-purple-400 hover:text-purple-300 text-sm">
86-
Resend
87-
</a>
88-
@endif
89-
</div>
90-
</div>
91-
</div>
92-
93-
<!-- Call Sign -->
94-
<div class="space-y-2">
95-
<label for="callSign" class="block text-sm font-medium leading-none text-slate-200">Call Sign</label>
96-
<input id="callSign" value="ALPHA-7" class="flex h-10 w-full rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-base text-slate-100 font-mono ring-offset-slate-950 placeholder:text-slate-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm" />
97-
</div>
98-
99-
<!-- Rank -->
100-
<div class="space-y-2">
101-
<label class="block text-sm font-medium leading-none text-slate-200">Rank</label>
102-
<div class="h-10 flex items-center">
103-
<span class="inline-flex items-center rounded-md border px-2.5 py-0.5 text-sm font-semibold border-slate-700 bg-slate-800 text-amber-400">
104-
<svg class="h-3 w-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8l-2 4h4l-2 4"/></svg>
105-
Captain
106-
</span>
107-
</div>
108-
</div>
109-
110-
<!-- Join Date -->
111-
<div class="space-y-2">
112-
<label class="block text-sm font-medium leading-none text-slate-200">Join Date</label>
113-
<div class="h-10 flex items-center text-slate-300">
114-
<svg class="h-4 w-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3M4 11h16M5 19h14a2 2 0 002-2v-7H3v7a2 2 0 002 2z"/></svg>
115-
2953.03.15
116-
</div>
117-
</div>
118-
119-
<!-- Flight Hours -->
120-
<div class="space-y-2">
121-
<label class="block text-sm font-medium leading-none text-slate-200">Flight Hours</label>
122-
<div class="h-10 flex items-center text-slate-300 font-mono">1,247</div>
123-
</div>
124-
</div>
125-
126-
<div class="flex justify-end pt-4">
127-
<button id="saveBtn" class="inline-flex items-center gap-2 h-9 px-4 bg-amber-400 text-slate-900 rounded-md text-sm font-medium hover:bg-amber-300">
128-
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
129-
Save Changes
130-
</button>
131-
</div>
132-
</form>
53+
<livewire:profile-main />
54+
13355
</div>
13456
</div>
13557

0 commit comments

Comments
 (0)