fipamo/app/Http/Controllers/Dash/AuthController.php
ro f7c9558da2
reorganized controller dir, added check for dash
seperated dash controllers for api controllers in the controller
directory to make them easier to manage

also added middleware to check authorization when accessing dash pages
2024-03-07 11:36:31 -06:00

50 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Dash;
use Symfony\Component\HttpFoundation\Response;
use App\Http\Controllers\Controller;
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/start');
} 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');
}
}