pianello-api/app/Http/Controllers/AuthController.php
Ale Gallo b91cf0cbde Committing laravel + api (part 1)
committing part of the laravel system with templating files and api implementation.
2023-11-10 15:54:41 +01:00

45 lines
922 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\View\View;
use App\Http\Requests\LoginRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
class AuthController extends Controller
{
/**
* Show specified view.
*/
public function loginView(): View
{
return view('login.main', [
'layout' => 'base'
]);
}
/**
* Authenticate login user.
*
* @param \Illuminate\Http\Request $request
*/
public function login(LoginRequest $request): void
{
if (!Auth::attempt([
'email' => $request->email,
'password' => $request->password
])) {
throw new \Exception('Wrong email or password.');
}
}
/**
* Logout user.
*/
public function logout(): RedirectResponse
{
Auth::logout();
return redirect('login');
}
}