ro
c77eeafb2c
Added controller to handle the login process and session management that stores information about the person that has logged in so that info is available through out the app when logged in
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use App\Services\AuthService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
public function __construct(
|
|
AuthService $authService
|
|
) {
|
|
$this->auth = $authService;
|
|
}
|
|
|
|
public function enter(Request $request): Response
|
|
{
|
|
$token = csrf_token();
|
|
|
|
$credentials = $request->validate([
|
|
'handle' => ['required'],
|
|
'password' => ['required'],
|
|
]);
|
|
|
|
if ($credentials) {
|
|
$result = $this->auth->check($request);
|
|
if ($result['status']) {
|
|
//$request->session()->regenerate();
|
|
return redirect()->intended('dashboard');
|
|
} else {
|
|
return back()->withErrors([
|
|
'error' => $result['message'],
|
|
]);
|
|
}
|
|
} else {
|
|
return back()->withErrors([
|
|
'error' => 'Nope. Check your crendtials, champ',
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function exit(Request $request): Response
|
|
{
|
|
session()->flush();
|
|
return redirect()->intended('dashboard');
|
|
}
|
|
}
|