Skip to content

Commit 2c5cd7c

Browse files
committed
feat: [LAR-102] wip on user setting
1 parent 83bc2fc commit 2c5cd7c

File tree

65 files changed

+506
-1249
lines changed

Some content is hidden

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

65 files changed

+506
-1249
lines changed

app/Http/Controllers/Cpanel/AnalyticsController.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/Http/Controllers/Cpanel/DashboardController.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/Http/Controllers/Cpanel/UserController.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/Http/Controllers/NotchPayCallBackController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Http\Request;
1212
use Illuminate\Support\Facades\Cache;
1313
use Illuminate\Support\Facades\Log;
14+
use NotchPay\Exceptions\ApiException;
1415
use NotchPay\NotchPay;
1516
use NotchPay\Payment;
1617

@@ -40,6 +41,7 @@ public function __invoke(Request $request): RedirectResponse
4041
} else {
4142
// @ToDO Envoie de mail de notification de remerciement pour le sponsoring si l'utilisateur est dans la base de données
4243
event(new SponsoringPaymentInitialize($transaction));
44+
4345
Cache::forget(key: 'sponsors');
4446

4547
session()->flash(
@@ -48,7 +50,7 @@ public function __invoke(Request $request): RedirectResponse
4850
);
4951
}
5052

51-
} catch (\NotchPay\Exceptions\ApiException $e) {
53+
} catch (ApiException $e) {
5254
Log::error($e->getMessage());
5355
session()->flash(
5456
key: 'error',

app/Http/Controllers/ReplyAbleController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
final class ReplyAbleController extends Controller
1111
{
12-
public function redirect(int $id, string $type): RedirectResponse
12+
public function __invoke(int $id, string $type): RedirectResponse
1313
{
14-
$reply = Reply::where('replyable_id', $id)->where('replyable_type', $type)->firstOrFail();
14+
$reply = Reply::query()
15+
->where('replyable_id', $id)
16+
->where('replyable_type', $type)
17+
->firstOrFail();
1518

1619
return redirect(route_to_reply_able($reply->replyAble));
1720
}

app/Http/Controllers/SubscriptionController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function unsubscribe(Subscribe $subscription): RedirectResponse
1414
/** @var \App\Models\Thread $thread */
1515
$thread = $subscription->subscribeAble;
1616

17-
$thread->subscribes()->where('user_id', $subscription->user->id)->delete(); // @phpstan-ignore-line
17+
$thread->subscribes()->where('user_id', $subscription->user->id)->delete();
1818

1919
session()->flash('status', __('Vous êtes maintenant désabonné de ce sujet.'));
2020

@@ -23,7 +23,10 @@ public function unsubscribe(Subscribe $subscription): RedirectResponse
2323

2424
public function redirect(int $id, string $type): RedirectResponse
2525
{
26-
$subscribe = Subscribe::where('subscribeable_id', $id)->where('subscribeable_type', $type)->firstOrFail();
26+
$subscribe = Subscribe::query()
27+
->where('subscribeable_id', $id)
28+
->where('subscribeable_type', $type)
29+
->firstOrFail();
2730

2831
return redirect(route_to_reply_able($subscribe->subscribeAble));
2932
}

app/Http/Controllers/User/ProfileController.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

app/Http/Controllers/User/SettingController.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020

2121
final class SettingController extends Controller
2222
{
23-
public function profile(): View
24-
{
25-
return view('user.settings.profile');
26-
}
27-
2823
public function update(UpdateProfileRequest $request): RedirectResponse
2924
{
3025
/** @var \App\Models\User $user */
@@ -55,40 +50,4 @@ public function update(UpdateProfileRequest $request): RedirectResponse
5550

5651
return redirect()->route('user.settings');
5752
}
58-
59-
public function password(): View
60-
{
61-
return view('user.settings.password', [
62-
'sessions' => Cache::remember('login-sessions', now()->addDays(5), function () {
63-
return DB::table('sessions')
64-
->where('user_id', auth()->id())
65-
->orderBy('last_activity', 'desc')
66-
->limit(3)
67-
->get()
68-
->map(fn ($session) => (object) [
69-
'agent' => $this->createAgent($session),
70-
'ip_address' => $session->ip_address,
71-
'is_current_device' => $session->id === request()->session()->getId(),
72-
'last_active' => Carbon::createFromTimestamp($session->last_activity)->diffForHumans(),
73-
'location' => Location::get($session->ip_address),
74-
]);
75-
}),
76-
]);
77-
}
78-
79-
public function updatePassword(UpdatePasswordRequest $request): RedirectResponse
80-
{
81-
Auth::user()->update(['password' => Hash::make($request->password)]); // @phpstan-ignore-line
82-
83-
session()->flash('status', __('Votre mot de passe a été changé avec succès.'));
84-
85-
return redirect()->back();
86-
}
87-
88-
protected function createAgent(mixed $session): mixed
89-
{
90-
return tap(new Agent, function ($agent) use ($session): void {
91-
$agent->setUserAgent($session->user_agent);
92-
});
93-
}
9453
}

app/Livewire/User/Settings/Notifications.php renamed to app/Livewire/Components/User/Notifications.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,55 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Livewire\User\Settings;
5+
namespace App\Livewire\Components\User;
66

77
use App\Models\Subscribe;
88
use Filament\Notifications\Notification;
99
use Illuminate\Contracts\View\View;
10-
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
1110
use Illuminate\Support\Facades\Auth;
11+
use Livewire\Attributes\Computed;
1212
use Livewire\Component;
1313

14+
/**
15+
* @property Subscribe $subscribe
16+
*/
1417
final class Notifications extends Component
1518
{
16-
use AuthorizesRequests;
17-
18-
public string $subscribeId;
19+
public ?string $subscribeId = null;
1920

2021
public function unsubscribe(string $subscribeId): void
2122
{
2223
$this->subscribeId = $subscribeId;
2324

24-
// @phpstan-ignore-next-line
2525
$this->subscribe->delete();
2626

2727
Notification::make()
2828
->title(__('Désabonnement'))
2929
->body(__('Vous êtes maintenant désabonné de cet fil.'))
3030
->success()
31-
->duration(5000)
31+
->duration(3500)
3232
->send();
3333
}
3434

35-
public function getSubscribeProperty(): Subscribe
35+
#[Computed]
36+
public function subscribe(): Subscribe
3637
{
37-
return Subscribe::where('uuid', $this->subscribeId)->firstOrFail();
38+
return Subscribe::query()->where('uuid', $this->subscribeId)->firstOrFail();
39+
}
40+
41+
public function redirectToSubscription(int $id, string $type): void
42+
{
43+
$subscribe = Subscribe::query()
44+
->where('subscribeable_id', $id)
45+
->where('subscribeable_type', $type)
46+
->firstOrFail();
47+
48+
$this->redirect(route_to_reply_able($subscribe->subscribeAble), navigate: true);
3849
}
3950

4051
public function render(): View
4152
{
42-
return view('livewire.user.settings.notifications', [
53+
return view('livewire.components.user.notifications', [
4354
'subscriptions' => Auth::user()->subscriptions, // @phpstan-ignore-line
4455
]);
4556
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Components\User;
6+
7+
use Filament\Forms;
8+
use Filament\Forms\Concerns\InteractsWithForms;
9+
use Filament\Forms\Contracts\HasForms;
10+
use Filament\Forms\Form;
11+
use Filament\Notifications\Notification;
12+
use Illuminate\Contracts\View\View;
13+
use Illuminate\Support\Facades\Auth;
14+
use Illuminate\Support\Facades\Hash;
15+
use Illuminate\Validation\Rules\Password as RulesPassword;
16+
use Livewire\Component;
17+
18+
/**
19+
* @property Form $form
20+
*/
21+
final class Password extends Component implements HasForms
22+
{
23+
use InteractsWithForms;
24+
25+
public ?array $data = [];
26+
27+
public function mount(): void
28+
{
29+
$this->form->fill();
30+
}
31+
32+
public function form(Form $form): Form
33+
{
34+
return $form
35+
->schema([
36+
Forms\Components\TextInput::make('current_password')
37+
->label(__('validation.attributes.current_password'))
38+
->password()
39+
->currentPassword()
40+
->required()
41+
->visible(fn () => Auth::user()->hasPassword()), // @phpstan-ignore-line
42+
Forms\Components\TextInput::make('password')
43+
->label(__('validation.attributes.password'))
44+
->helperText(__('pages/account.settings.password_helpText'))
45+
->password()
46+
->revealable()
47+
->required()
48+
->rules(fn () => [
49+
RulesPassword::min(8)
50+
->mixedCase()
51+
->symbols()
52+
->letters()
53+
->numbers()
54+
->uncompromised(),
55+
])
56+
->confirmed(),
57+
Forms\Components\TextInput::make('password_confirmation')
58+
->label(__('validation.attributes.password_confirmation'))
59+
->password()
60+
->revealable()
61+
->required(),
62+
])
63+
->statePath('data')
64+
->model(Auth::user());
65+
}
66+
67+
public function changePassword(): void
68+
{
69+
$this->validate();
70+
71+
// @phpstan-ignore-next-line
72+
Auth::user()->update([
73+
'password' => Hash::make(
74+
value: data_get($this->form->getState(), 'password')
75+
),
76+
]);
77+
78+
Notification::make()
79+
->success()
80+
->title(__('notifications.user.password_changed'))
81+
->duration(3500)
82+
->send();
83+
}
84+
85+
public function render(): View
86+
{
87+
return view('livewire.components.user.password');
88+
}
89+
}

0 commit comments

Comments
 (0)