2024-02-29 13:00:59 -06:00
|
|
|
<?php
|
|
|
|
|
2024-05-09 11:24:12 -06:00
|
|
|
namespace App\Http\Controllers;
|
2024-02-29 13:00:59 -06:00
|
|
|
|
2025-05-17 08:03:46 -06:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2024-03-05 13:27:27 -06:00
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
2024-05-13 12:06:05 -06:00
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
2025-05-16 17:37:53 -06:00
|
|
|
use App\Services\Assets\FileUploadService;
|
|
|
|
use Illuminate\Http\Request;
|
2024-03-01 13:34:36 -06:00
|
|
|
|
2024-05-09 11:24:12 -06:00
|
|
|
class DashController extends Controller
|
2024-02-29 13:00:59 -06:00
|
|
|
{
|
2024-03-05 13:27:27 -06:00
|
|
|
protected PageRepositoryInterface $pages;
|
2024-05-13 12:06:05 -06:00
|
|
|
protected MemberRepositoryInterface $member;
|
2025-05-16 17:37:53 -06:00
|
|
|
protected FileUploadService $upload;
|
2024-02-29 13:00:59 -06:00
|
|
|
|
2024-03-01 13:34:36 -06:00
|
|
|
public function __construct(
|
2024-03-05 13:27:27 -06:00
|
|
|
PageRepositoryInterface $pageRepository,
|
2024-05-13 12:06:05 -06:00
|
|
|
MemberRepositoryInterface $memberRepo,
|
2025-05-16 17:37:53 -06:00
|
|
|
FileUploadService $fileUploadService,
|
2024-03-01 13:34:36 -06:00
|
|
|
) {
|
2024-03-06 10:27:41 -06:00
|
|
|
$this->pages = $pageRepository;
|
2024-05-13 12:06:05 -06:00
|
|
|
$this->member = $memberRepo;
|
2025-05-16 17:37:53 -06:00
|
|
|
$this->upload = $fileUploadService;
|
2024-02-29 13:00:59 -06:00
|
|
|
}
|
|
|
|
|
2024-07-13 14:23:01 -06:00
|
|
|
//---
|
|
|
|
// GET
|
|
|
|
//---
|
|
|
|
|
2024-03-03 19:50:14 -06:00
|
|
|
public function start()
|
2024-02-29 13:00:59 -06:00
|
|
|
{
|
2024-05-13 12:06:05 -06:00
|
|
|
if ($this->member::status()) {
|
2025-05-17 08:03:46 -06:00
|
|
|
$result = [];
|
2024-03-05 13:27:27 -06:00
|
|
|
$result = $this->pages->getGroup(1, 4);
|
2025-05-16 17:37:53 -06:00
|
|
|
return view('back.start', [
|
|
|
|
"status" => $this->member::status(),
|
|
|
|
"result" => $result,
|
|
|
|
"title" => "Start"
|
|
|
|
]);
|
2025-05-08 18:25:57 -06:00
|
|
|
} else {
|
2025-05-16 17:37:53 -06:00
|
|
|
return view('back.login', [
|
|
|
|
"status" => $this->member::status(),
|
|
|
|
"title" => "Hi!"
|
|
|
|
]);
|
|
|
|
}
|
2024-03-19 13:19:27 -06:00
|
|
|
}
|
2024-05-09 11:24:12 -06:00
|
|
|
|
2025-05-17 08:03:46 -06:00
|
|
|
public function exit()
|
|
|
|
{
|
|
|
|
session()->flush();
|
|
|
|
return redirect()->intended('dashboard');
|
|
|
|
}
|
|
|
|
|
2024-07-13 14:23:01 -06:00
|
|
|
//---
|
|
|
|
// POST
|
|
|
|
//---
|
2025-05-17 08:03:46 -06:00
|
|
|
public function enter(Request $request): Response
|
|
|
|
{
|
|
|
|
$token = csrf_token();
|
|
|
|
|
|
|
|
$credentials = $request->validate([
|
|
|
|
'handle' => ['required'],
|
|
|
|
'password' => ['required'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($credentials) {
|
|
|
|
$result = $this->member->auth($request);
|
|
|
|
if ($result['status']) {
|
|
|
|
//$request->session()->regenerate();
|
|
|
|
return redirect()->intended('dashboard');
|
|
|
|
//return $this->start();
|
|
|
|
} else {
|
|
|
|
return back()->withErrors([
|
|
|
|
'error' => $result['message'],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return back()->withErrors([
|
|
|
|
'error' => 'Nope. Check your crendtials, champ',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-16 17:37:53 -06:00
|
|
|
public function uploads(Request $request)
|
|
|
|
{
|
|
|
|
$result = $result = $this->upload->handleFile($request);
|
|
|
|
//update configs for specfic uploads
|
|
|
|
switch ($request['source']) {
|
|
|
|
case 'avatar-upload':
|
|
|
|
$member = [];
|
|
|
|
$member = session('member');
|
|
|
|
$member['avatar'] = $result['filePath'];
|
|
|
|
$member = (object) $member;
|
|
|
|
$this->member->update($member);
|
|
|
|
break;
|
|
|
|
case 'background-upload':
|
|
|
|
$this->settings->updateGlobalData('background', $result['filePath']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2024-02-29 13:00:59 -06:00
|
|
|
}
|