2024-08-07 18:08:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2024-08-09 10:37:35 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Validation\ValidationException;
|
2024-08-07 18:08:20 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class SessionController extends Controller
|
|
|
|
{
|
|
|
|
public function create()
|
|
|
|
{
|
2024-08-08 11:22:35 +02:00
|
|
|
return view('auth.login');
|
2024-08-07 18:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store()
|
|
|
|
{
|
|
|
|
$validatedAttributes = request()->validate([
|
|
|
|
'email' => ['required', 'email'],
|
|
|
|
'password' => ['required'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if( !Auth::attempt($validatedAttributes) )
|
|
|
|
{
|
2024-08-09 10:37:35 +02:00
|
|
|
throw ValidationException::withMessages(['email' => 'credentials do not match']);
|
2024-08-07 18:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
request()->session()->regenerate();
|
|
|
|
|
2024-08-09 13:52:23 +02:00
|
|
|
return redirect('/articles');
|
2024-08-07 18:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy()
|
|
|
|
{
|
|
|
|
Auth::logout();
|
|
|
|
|
|
|
|
return redirect('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|