2024-07-13 22:23:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
use App\Mail\SystemEmail;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
2024-07-17 23:08:10 +02:00
|
|
|
use App\Services\Upkeep\MaintenanceService;
|
|
|
|
use App\Services\Assets\FileUploadService;
|
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
|
|
|
use App\Services\Data\SettingsService;
|
2024-08-31 00:14:15 +02:00
|
|
|
use App\Services\Upkeep\InitService;
|
|
|
|
use App\Services\Upkeep\ResetService;
|
2024-07-13 22:23:01 +02:00
|
|
|
|
|
|
|
class RoutePostController extends Controller
|
|
|
|
{
|
|
|
|
protected $page;
|
2024-07-17 23:08:10 +02:00
|
|
|
protected $gate;
|
|
|
|
protected $maintenance;
|
|
|
|
protected $upload;
|
|
|
|
protected $settings;
|
|
|
|
protected $member;
|
|
|
|
protected $init;
|
|
|
|
protected $reset;
|
2024-07-13 22:23:01 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
PageRepositoryInterface $pageRepo,
|
|
|
|
AuthController $authController,
|
2024-07-17 23:08:10 +02:00
|
|
|
MaintenanceService $maintenanceService,
|
|
|
|
FileUploadService $fileUploadService,
|
|
|
|
SettingsService $settingsService,
|
|
|
|
MemberRepositoryInterface $memberRepo,
|
|
|
|
InitService $initService,
|
|
|
|
ResetService $resetService,
|
2024-07-13 22:23:01 +02:00
|
|
|
) {
|
2024-07-17 23:08:10 +02:00
|
|
|
$this->page = $pageRepo;
|
|
|
|
$this->gate = $authController;
|
|
|
|
$this->maintenance = $maintenanceService;
|
|
|
|
$this->upload = $fileUploadService;
|
|
|
|
$this->settings = $settingsService;
|
|
|
|
$this->member = $memberRepo;
|
|
|
|
$this->init = $initService;
|
|
|
|
$this->reset = $resetService;
|
2024-07-13 22:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(Request $request)
|
|
|
|
{
|
|
|
|
$path = explode('/', $request->path());
|
|
|
|
switch ($path[0]) {
|
2024-07-17 23:08:10 +02:00
|
|
|
case 'init':
|
|
|
|
return $this->initTask($path[1], $request);
|
|
|
|
break;
|
2024-07-13 22:23:01 +02:00
|
|
|
case 'login':
|
|
|
|
return $this->gate->enter($request);
|
|
|
|
break;
|
|
|
|
case 'page':
|
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
$result = $this->page->create($body);
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
break;
|
|
|
|
case 'settings':
|
|
|
|
if ($path[1] == 'mailer') {
|
|
|
|
return $this->sendNotify($request);
|
|
|
|
}
|
|
|
|
break;
|
2024-07-17 23:08:10 +02:00
|
|
|
case 'upload':
|
2024-07-24 01:46:45 +02:00
|
|
|
$result = $result = $this->upload->handleFile($request);
|
2024-07-17 23:08:10 +02:00
|
|
|
//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;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function initTask($task, $request)
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
switch ($task) {
|
|
|
|
case 'fresh':
|
|
|
|
$result = $this->init->fresh(json_decode($request->getContent()));
|
|
|
|
break;
|
|
|
|
case 'restore':
|
|
|
|
$result = $this->init->restore($request);
|
|
|
|
break;
|
|
|
|
case 'reset':
|
|
|
|
$result = $this->reset->site($request);
|
|
|
|
break;
|
2024-07-13 22:23:01 +02:00
|
|
|
}
|
2024-07-17 23:08:10 +02:00
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
2024-07-13 22:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function sendNotify($request)
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
try {
|
|
|
|
Mail::to(env('ADMIN_EMAIL'))->send(new SystemEmail($request->content));
|
|
|
|
$result = [
|
|
|
|
'type' => 'mail_good',
|
|
|
|
'message' => 'Mail Sent',
|
|
|
|
];
|
|
|
|
} catch (TransportException $e) {
|
|
|
|
$result = [
|
|
|
|
'type' => 'mail_not_good',
|
|
|
|
'message' => 'Mail Not Sent. It\'s cool. Just check mail settings in the .env',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
}
|
|
|
|
}
|