2024-03-03 20:48:22 +01:00
|
|
|
<?php
|
|
|
|
|
2024-05-09 19:24:12 +02:00
|
|
|
namespace App\Http\Controllers;
|
2024-03-03 20:48:22 +01:00
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2024-05-13 06:14:53 +02:00
|
|
|
use App\Services\Data\AuthService;
|
2024-03-03 20:48:22 +01:00
|
|
|
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();
|
2024-03-07 18:36:31 +01:00
|
|
|
return redirect()->intended('dashboard/start');
|
2024-03-03 20:48:22 +01:00
|
|
|
} 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');
|
|
|
|
}
|
|
|
|
}
|