Skip to content

Commit c512f79

Browse files
committed
feat: (LAR-77) Mise en place de la class Login, et correction de la connexion
1 parent 878b7f3 commit c512f79

File tree

8 files changed

+297
-174
lines changed

8 files changed

+297
-174
lines changed

app/Livewire/Forms/LoginForm.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
use Illuminate\Support\Facades\RateLimiter;
88
use Illuminate\Support\Str;
99
use Illuminate\Validation\ValidationException;
10-
use Livewire\Attributes\Validate;
1110
use Livewire\Form;
11+
use Livewire\Component;
1212

1313
class LoginForm extends Form
1414
{
15-
#[Validate('required|string|email')]
1615
public string $email = '';
17-
18-
#[Validate('required|string')]
1916
public string $password = '';
20-
21-
#[Validate('boolean')]
2217
public bool $remember = false;
2318

19+
public function __construct(Component $component = null, $name = 'form')
20+
{
21+
parent::__construct($component, $name);
22+
}
23+
2424
/**
2525
* Attempt to authenticate the request's credentials.
2626
*
@@ -30,7 +30,7 @@ public function authenticate(): void
3030
{
3131
$this->ensureIsNotRateLimited();
3232

33-
if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) {
33+
if (! Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) {
3434
RateLimiter::hit($this->throttleKey());
3535

3636
throw ValidationException::withMessages([
@@ -69,4 +69,4 @@ protected function throttleKey(): string
6969
{
7070
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
7171
}
72-
}
72+
}

app/Livewire/Pages/Auth/Login.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Livewire\Pages\Auth;
4+
5+
use App\Livewire\Forms\LoginForm;
6+
use Illuminate\Support\Facades\Session;
7+
use Livewire\Component;
8+
use Livewire\Attributes\Layout;
9+
10+
// #[Layout('layouts.guest')]
11+
class Login extends Component
12+
{
13+
public LoginForm $form;
14+
15+
public function boot()
16+
{
17+
$this->form = new LoginForm($this);
18+
}
19+
20+
public function login(): void
21+
{
22+
$this->validate([
23+
'form.email' => ['required', 'email'],
24+
'form.password' => ['required'],
25+
'form.remember' => ['boolean'],
26+
]);
27+
28+
$this->form->authenticate();
29+
30+
Session::regenerate();
31+
32+
$this->redirectIntended(route('dashboard'));
33+
}
34+
35+
public function render()
36+
{
37+
return view('livewire.pages.auth.login');
38+
}
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@props(['messages'])
2+
3+
@if ($messages)
4+
<ul {{ $attributes->merge(['class' => 'text-sm text-red-600 dark:text-red-400 space-y-1']) }}>
5+
@foreach ((array) $messages as $message)
6+
<li>{{ $message }}</li>
7+
@endforeach
8+
</ul>
9+
@endif

resources/views/components/input-label.blade.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
<label {{ $attributes->merge(['class' => 'block font-medium text-sm text-gray-700 dark:text-gray-300']) }}>
44
{{ $value ?? $slot }}
5-
</label>
6-
7-
8-
Repète voir stp pb de reseau !!!!
5+
</label
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<button {{ $attributes->merge(['type' => 'submit', 'class' => 'inline-flex items-center px-4 py-2 bg-gray-800 dark:bg-gray-200 border border-transparent rounded-md font-semibold text-xs text-white dark:text-gray-800 uppercase tracking-widest hover:bg-gray-700 dark:hover:bg-white focus:bg-gray-700 dark:focus:bg-white active:bg-gray-900 dark:active:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800 transition ease-in-out duration-150']) }}>
2+
{{ $slot }}
3+
</button>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@props(['disabled' => false])
2+
3+
<input @disabled($disabled) {{ $attributes->merge(['class' => 'border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm']) }}>

resources/views/livewire/pages/auth/login.blade.php

Lines changed: 90 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,96 @@ public function login(): void
2525
$this->redirectIntended(default: route('dashboard', absolute: false), navigate: true);
2626
}
2727
}; ?>
28-
29-
<div>
30-
<!-- Session Status -->
31-
<x-status-message class="mb-4" :status="session('status')" />
32-
33-
<form wire:submit="login">
34-
<!-- Email Address -->
35-
<div>
36-
<x-input-label for="email" :value="__('Email')" />
37-
<x-text-input wire:model="form.email" id="email" class="block mt-1 w-full" type="email" name="email" required autofocus autocomplete="username" />
38-
<x-input-error :messages="$errors->get('form.email')" class="mt-2" />
39-
</div>
40-
41-
<!-- Password -->
42-
<div class="mt-4">
43-
<x-input-label for="password" :value="__('Password')" />
44-
45-
<x-text-input wire:model="form.password" id="password" class="block mt-1 w-full"
46-
type="password"
47-
name="password"
48-
required autocomplete="current-password" />
49-
50-
<x-input-error :messages="$errors->get('form.password')" class="mt-2" />
51-
</div>
52-
53-
<!-- Remember Me -->
54-
<div class="block mt-4">
55-
<label for="remember" class="inline-flex items-center">
56-
<input wire:model="form.remember" id="remember" type="checkbox" class="rounded dark:bg-gray-900 border-gray-300 dark:border-gray-700 text-indigo-600 shadow-sm focus:ring-indigo-500 dark:focus:ring-indigo-600 dark:focus:ring-offset-gray-800" name="remember">
57-
<span class="ms-2 text-sm text-gray-600 dark:text-gray-400">{{ __('Remember me') }}</span>
58-
</label>
59-
</div>
60-
61-
<div class="flex items-center justify-end mt-4">
62-
@if (Route::has('password.request'))
63-
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('password.request') }}" wire:navigate>
64-
{{ __('Forgot your password?') }}
65-
</a>
66-
@endif
67-
68-
<x-primary-button class="ms-3">
69-
{{ __('Log in') }}
70-
</x-primary-button>
71-
</div>
72-
</form>
73-
</div>
74-
28+
{{-- <x-app-layout :title="__('pages/auth.login.page_title')"> --}}
29+
<div>
30+
<x-container class="flex min-h-full items-center justify-center py-16 sm:pt-24">
31+
<div class="w-full max-w-md space-y-8">
32+
<div>
33+
<h2 class="text-center font-heading text-3xl font-extrabold text-gray-900 dark:text-white">
34+
{{ __('pages/auth.login.title') }}
35+
</h2>
36+
</div>
37+
<form class="space-y-6" wire:submit.prevent="login">
38+
@csrf
39+
<div class="space-y-4">
40+
<!-- Email Input -->
41+
<div class="space-y-1">
42+
<label for="email" class="block text-sm font-medium text-gray-700 dark:text-gray-300">
43+
{{ __('validation.attributes.email') }}
44+
</label>
45+
<x-text-input
46+
type="email"
47+
id="email"
48+
wire:model="form.email"
49+
name="email"
50+
required
51+
placeholder="{{ __('validation.attributes.email') }}"
52+
class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
53+
/>
54+
@error('form.email')
55+
<span class="text-sm text-red-500">{{ $message }}</span>
56+
@enderror
57+
</div>
58+
59+
<!-- Password Input -->
60+
<div class="space-y-1">
61+
<label for="password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">
62+
{{ __('validation.attributes.password') }}
63+
</label>
64+
<x-text-input
65+
type="password"
66+
id="password"
67+
wire:model="form.password"
68+
name="password"
69+
required
70+
placeholder="{{ __('validation.attributes.password') }}"
71+
class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
72+
/>
73+
@error('form.password')
74+
<span class="text-sm text-red-500">{{ $message }}</span>
75+
@enderror
76+
</div>
77+
</div>
78+
79+
<div class="flex items-center justify-between">
80+
<!-- Remember Me Checkbox -->
81+
<div class="flex items-center">
82+
<input
83+
type="checkbox"
84+
id="remember_me"
85+
wire:model="form.remember"
86+
class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded"
87+
/>
88+
<label for="remember_me" class="ml-2 block text-sm text-gray-500 dark:text-gray-400">
89+
{{ __('pages/auth.login.remember_me') }}
90+
</label>
91+
</div>
92+
93+
<!-- Forgot Password Link -->
94+
<div class="text-sm">
95+
<a href="{{ route('password.request') }}" class="font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-white">
96+
{{ __('pages/auth.login.forgot_password') }}
97+
</a>
98+
</div>
99+
</div>
100+
101+
<div>
102+
<x-buttons.primary type="submit" class="group relative w-full">
103+
<span class="absolute pointer-events-none inset-y-0 left-0 flex items-center pl-3">
104+
<x-untitledui-lock class="size-5 text-green-500 group-hover:text-green-600" aria-hidden="true" />
105+
</span>
106+
{{ __('pages/auth.login.submit') }}
107+
</x-buttons.primary>
108+
</div>
109+
</form>
110+
@include('partials._socials-link')
111+
</div>
112+
</x-container>
113+
114+
<x-join-sponsors :title="__('global.sponsor_thanks')" />
115+
</div>
116+
117+
{{-- </x-app-layout> --}}
75118

76119

77120
{{-- <x-app-layout :title="__('pages/auth.login.page_title')">

0 commit comments

Comments
 (0)