dym-sh/app/Http/Controllers/SessionController.php

39 lines
721 B
PHP
Raw Normal View History

2024-08-07 18:08:20 +02:00
<?php
namespace App\Http\Controllers;
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) )
{
throw ValidationException::withMessages(['email' => 'wrong password']);
}
request()->session()->regenerate();
return redirect('/admin');
}
public function destroy()
{
Auth::logout();
return redirect('/');
}
}