forked from projects/fipamo
ro
3d17771f76
The first part of improving the API is removing all admin functions from the front end so those no admin methods will be available client side. The urls in the FipamoAdmin js file have been changed to post directly to the system and they are handled from there. To account for this change controller routes for every standard method have been created for better organization and readability. The FipamoAdmin js file will be integrated with the rest of the front end code and will not be seperate library
61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use App\Mail\SystemEmail;
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
|
|
class RoutePostController extends Controller
|
|
{
|
|
protected $page;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepo,
|
|
AuthController $authController,
|
|
) {
|
|
$this->page = $pageRepo;
|
|
$this->gate = $authController;
|
|
}
|
|
|
|
public function handleRequest(Request $request)
|
|
{
|
|
$path = explode('/', $request->path());
|
|
switch ($path[0]) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|