Skip to content

Commit 7c5168a

Browse files
committed
feat : livewire and jetstream added and config.
1 parent cb2e36f commit 7c5168a

File tree

98 files changed

+5724
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+5724
-45
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BROADCAST_DRIVER=log
1919
CACHE_DRIVER=file
2020
FILESYSTEM_DISK=local
2121
QUEUE_CONNECTION=sync
22-
SESSION_DRIVER=file
22+
SESSION_DRIVER=database
2323
SESSION_LIFETIME=120
2424

2525
MEMCACHED_HOST=127.0.0.1

app/Actions/Fortify/CreateNewUser.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Laravel\Fortify\Contracts\CreatesNewUsers;
9+
use Laravel\Jetstream\Jetstream;
10+
11+
class CreateNewUser implements CreatesNewUsers
12+
{
13+
use PasswordValidationRules;
14+
15+
/**
16+
* Validate and create a newly registered user.
17+
*
18+
* @param array<string, string> $input
19+
*/
20+
public function create(array $input): User
21+
{
22+
Validator::make($input, [
23+
'name' => ['required', 'string', 'max:255'],
24+
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
25+
'password' => $this->passwordRules(),
26+
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
27+
])->validate();
28+
29+
return User::create([
30+
'name' => $input['name'],
31+
'email' => $input['email'],
32+
'password' => Hash::make($input['password']),
33+
]);
34+
}
35+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use Illuminate\Validation\Rules\Password;
6+
7+
trait PasswordValidationRules
8+
{
9+
/**
10+
* Get the validation rules used to validate passwords.
11+
*
12+
* @return array<int, \Illuminate\Contracts\Validation\Rule|array<mixed>|string>
13+
*/
14+
protected function passwordRules(): array
15+
{
16+
return ['required', 'string', Password::default(), 'confirmed'];
17+
}
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Laravel\Fortify\Contracts\ResetsUserPasswords;
9+
10+
class ResetUserPassword implements ResetsUserPasswords
11+
{
12+
use PasswordValidationRules;
13+
14+
/**
15+
* Validate and reset the user's forgotten password.
16+
*
17+
* @param array<string, string> $input
18+
*/
19+
public function reset(User $user, array $input): void
20+
{
21+
Validator::make($input, [
22+
'password' => $this->passwordRules(),
23+
])->validate();
24+
25+
$user->forceFill([
26+
'password' => Hash::make($input['password']),
27+
])->save();
28+
}
29+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Support\Facades\Hash;
7+
use Illuminate\Support\Facades\Validator;
8+
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
9+
10+
class UpdateUserPassword implements UpdatesUserPasswords
11+
{
12+
use PasswordValidationRules;
13+
14+
/**
15+
* Validate and update the user's password.
16+
*
17+
* @param array<string, string> $input
18+
*/
19+
public function update(User $user, array $input): void
20+
{
21+
Validator::make($input, [
22+
'current_password' => ['required', 'string', 'current_password:web'],
23+
'password' => $this->passwordRules(),
24+
], [
25+
'current_password.current_password' => __('The provided password does not match your current password.'),
26+
])->validateWithBag('updatePassword');
27+
28+
$user->forceFill([
29+
'password' => Hash::make($input['password']),
30+
])->save();
31+
}
32+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Actions\Fortify;
4+
5+
use App\Models\User;
6+
use Illuminate\Contracts\Auth\MustVerifyEmail;
7+
use Illuminate\Support\Facades\Validator;
8+
use Illuminate\Validation\Rule;
9+
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
10+
11+
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
12+
{
13+
/**
14+
* Validate and update the given user's profile information.
15+
*
16+
* @param array<string, mixed> $input
17+
*/
18+
public function update(User $user, array $input): void
19+
{
20+
Validator::make($input, [
21+
'name' => ['required', 'string', 'max:255'],
22+
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
23+
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
24+
])->validateWithBag('updateProfileInformation');
25+
26+
if (isset($input['photo'])) {
27+
$user->updateProfilePhoto($input['photo']);
28+
}
29+
30+
if ($input['email'] !== $user->email &&
31+
$user instanceof MustVerifyEmail) {
32+
$this->updateVerifiedUser($user, $input);
33+
} else {
34+
$user->forceFill([
35+
'name' => $input['name'],
36+
'email' => $input['email'],
37+
])->save();
38+
}
39+
}
40+
41+
/**
42+
* Update the given verified user's profile information.
43+
*
44+
* @param array<string, string> $input
45+
*/
46+
protected function updateVerifiedUser(User $user, array $input): void
47+
{
48+
$user->forceFill([
49+
'name' => $input['name'],
50+
'email' => $input['email'],
51+
'email_verified_at' => null,
52+
])->save();
53+
54+
$user->sendEmailVerificationNotification();
55+
}
56+
}

app/Actions/Jetstream/DeleteUser.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Actions\Jetstream;
4+
5+
use App\Models\User;
6+
use Laravel\Jetstream\Contracts\DeletesUsers;
7+
8+
class DeleteUser implements DeletesUsers
9+
{
10+
/**
11+
* Delete the given user.
12+
*/
13+
public function delete(User $user): void
14+
{
15+
$user->deleteProfilePhoto();
16+
$user->tokens->each->delete();
17+
$user->delete();
18+
}
19+
}

app/Models/User.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Foundation\Auth\User as Authenticatable;
88
use Illuminate\Notifications\Notifiable;
9+
use Laravel\Fortify\TwoFactorAuthenticatable;
10+
use Laravel\Jetstream\HasProfilePhoto;
911
use Laravel\Sanctum\HasApiTokens;
1012

1113
class User extends Authenticatable
1214
{
13-
use HasApiTokens, HasFactory, Notifiable;
15+
use HasApiTokens;
16+
use HasFactory;
17+
use HasProfilePhoto;
18+
use Notifiable;
19+
use TwoFactorAuthenticatable;
1420

1521
/**
1622
* The attributes that are mass assignable.
@@ -31,6 +37,8 @@ class User extends Authenticatable
3137
protected $hidden = [
3238
'password',
3339
'remember_token',
40+
'two_factor_recovery_codes',
41+
'two_factor_secret',
3442
];
3543

3644
/**
@@ -41,4 +49,13 @@ class User extends Authenticatable
4149
protected $casts = [
4250
'email_verified_at' => 'datetime',
4351
];
52+
53+
/**
54+
* The accessors to append to the model's array form.
55+
*
56+
* @var array<int, string>
57+
*/
58+
protected $appends = [
59+
'profile_photo_url',
60+
];
4461
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use App\Actions\Fortify\CreateNewUser;
6+
use App\Actions\Fortify\ResetUserPassword;
7+
use App\Actions\Fortify\UpdateUserPassword;
8+
use App\Actions\Fortify\UpdateUserProfileInformation;
9+
use Illuminate\Cache\RateLimiting\Limit;
10+
use Illuminate\Http\Request;
11+
use Illuminate\Support\Facades\RateLimiter;
12+
use Illuminate\Support\ServiceProvider;
13+
use Illuminate\Support\Str;
14+
use Laravel\Fortify\Fortify;
15+
16+
class FortifyServiceProvider extends ServiceProvider
17+
{
18+
/**
19+
* Register any application services.
20+
*/
21+
public function register(): void
22+
{
23+
//
24+
}
25+
26+
/**
27+
* Bootstrap any application services.
28+
*/
29+
public function boot(): void
30+
{
31+
Fortify::createUsersUsing(CreateNewUser::class);
32+
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
33+
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
34+
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
35+
36+
RateLimiter::for('login', function (Request $request) {
37+
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
38+
39+
return Limit::perMinute(5)->by($throttleKey);
40+
});
41+
42+
RateLimiter::for('two-factor', function (Request $request) {
43+
return Limit::perMinute(5)->by($request->session()->get('login.id'));
44+
});
45+
}
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use App\Actions\Jetstream\DeleteUser;
6+
use Illuminate\Support\ServiceProvider;
7+
use Laravel\Jetstream\Jetstream;
8+
9+
class JetstreamServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Register any application services.
13+
*/
14+
public function register(): void
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Bootstrap any application services.
21+
*/
22+
public function boot(): void
23+
{
24+
$this->configurePermissions();
25+
26+
Jetstream::deleteUsersUsing(DeleteUser::class);
27+
}
28+
29+
/**
30+
* Configure the permissions that are available within the application.
31+
*/
32+
protected function configurePermissions(): void
33+
{
34+
Jetstream::defaultApiTokenPermissions(['read']);
35+
36+
Jetstream::permissions([
37+
'create',
38+
'read',
39+
'update',
40+
'delete',
41+
]);
42+
}
43+
}

app/Providers/RouteServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
1717
*
1818
* @var string
1919
*/
20-
public const HOME = '/home';
20+
public const HOME = '/dashboard';
2121

2222
/**
2323
* Define your route model bindings, pattern filters, and other route configuration.

app/View/Components/AppLayout.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\View\Components;
4+
5+
use Illuminate\View\Component;
6+
use Illuminate\View\View;
7+
8+
class AppLayout extends Component
9+
{
10+
/**
11+
* Get the view / contents that represents the component.
12+
*/
13+
public function render(): View
14+
{
15+
return view('layouts.app');
16+
}
17+
}

app/View/Components/GuestLayout.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\View\Components;
4+
5+
use Illuminate\View\Component;
6+
use Illuminate\View\View;
7+
8+
class GuestLayout extends Component
9+
{
10+
/**
11+
* Get the view / contents that represents the component.
12+
*/
13+
public function render(): View
14+
{
15+
return view('layouts.guest');
16+
}
17+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"laravel/framework": "^10.0",
1111
"laravel/jetstream": "^4.3",
1212
"laravel/sanctum": "^3.2",
13-
"laravel/tinker": "^2.8"
13+
"laravel/tinker": "^2.8",
14+
"livewire/livewire": "^3.0"
1415
},
1516
"require-dev": {
1617
"fakerphp/faker": "^1.9.1",

0 commit comments

Comments
 (0)