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 20:06:05 +02:00
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
2024-03-03 20:48:22 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class AuthController extends Controller
|
|
|
|
{
|
2024-05-13 20:06:05 +02:00
|
|
|
protected $member;
|
|
|
|
|
2024-03-03 20:48:22 +01:00
|
|
|
public function __construct(
|
2024-05-13 20:06:05 +02:00
|
|
|
MemberRepositoryInterface $memberRepository
|
2024-03-03 20:48:22 +01:00
|
|
|
) {
|
2024-05-13 20:06:05 +02:00
|
|
|
$this->member = $memberRepository;
|
2024-03-03 20:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function enter(Request $request): Response
|
|
|
|
{
|
|
|
|
$token = csrf_token();
|
|
|
|
|
|
|
|
$credentials = $request->validate([
|
|
|
|
'handle' => ['required'],
|
|
|
|
'password' => ['required'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($credentials) {
|
2024-05-13 20:06:05 +02:00
|
|
|
$result = $this->member->auth($request);
|
2024-03-03 20:48:22 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|