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
This commit is contained in:
ro 2024-03-07 11:36:31 -06:00
parent 1e37580869
commit f7c9558da2
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
8 changed files with 108 additions and 57 deletions

View file

@ -1,8 +1,9 @@
<?php
namespace App\Http\Controllers;
namespace App\Http\Controllers\Dash;
use Symfony\Component\HttpFoundation\Response;
use App\Http\Controllers\Controller;
use App\Services\AuthService;
use Illuminate\Http\Request;
@ -27,7 +28,7 @@ class AuthController extends Controller
$result = $this->auth->check($request);
if ($result['status']) {
//$request->session()->regenerate();
return redirect()->intended('dashboard');
return redirect()->intended('dashboard/start');
} else {
return back()->withErrors([
'error' => $result['message'],

View file

@ -1,12 +1,13 @@
<?php
namespace App\Http\Controllers;
namespace App\Http\Controllers\Dash;
use App\Interfaces\PageRepositoryInterface;
use App\Services\AuthService;
use App\Services\ThemeService;
use App\Http\Controllers\Controller;
class DashController extends Controller
class IndexController extends Controller
{
protected PageRepositoryInterface $pages;
protected AuthService $auth;
@ -22,6 +23,18 @@ class DashController extends Controller
$this->themes = $themeService;
}
public function login()
{
if ($this->auth::status()) {
return redirect('dashboard/start');
} else {
return view('back.login', [
"status" => $this->auth::status(),
"title" => "Hi!"
]);
}
}
public function start()
{
$result = [];

View file

@ -64,5 +64,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'member.check' => \App\Http\Middleware\MemberCheck::class,
];
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use App\Services\AuthService;
class MemberCheck
{
protected $auth;
public function __construct(
AuthService $authService,
) {
$this->auth = $authService;
}
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next)
{
if ($this->auth::status()) {
return $next($request);
} else {
return redirect('dashboard');
}
}
}

View file

@ -0,0 +1,7 @@
@extends('frame')
@section('title', 'The Dash | Start')
@section('main-content')
@include('forms.login')
@endsection

View file

@ -3,9 +3,36 @@
@section('title', 'The Dash | Start')
@section('main-content')
@if($status)
@include('includes.index')
<section class="index-header">
<div class="index-header-left">
<h1>Recent</h1>
</div>
<div class="index-header-right"></div>
</section>
<section class="index-recent-pages">
@if($result['entryCount'] != 0)
@foreach($result['pages'] as $page)
@php
$type = '';
$file = '';
isset($page['media'][0]['type']) ? $type = $page['media'][0]['type'] : $type = '';
isset($page['media'][0]['file']) ? $file = $page['media'][0]['file'] : $file = '';
@endphp
@if($type =='mp4')
<a href="/dashboard/page/edit/{{ $page['uuid'] }}" id="{{ $page['uuid'] }}" class="post-video-link recent-link">
@include('includes.recent-meta')
<video class="post-video" loop muted autoplay>
<source src="{{ $file }}" type="video/mp4">
Sorry, your browser doesn't support embedded videos.
</video>
</a>
@else
@include('forms.login')
<a href="/dashboard/page/edit/{{ $page['uuid'] }}" id="{{ $page['uuid'] }}" class="post-link recent-link" style="background: url({{ $file }}) no-repeat center center / cover #fc6399">
@include('includes.recent-meta')
</a>
@endif
@endforeach
@endif
</section>
@endsection

View file

@ -1,31 +0,0 @@
<section class="index-header">
<div class="index-header-left">
<h1>Recent</h1>
</div>
<div class="index-header-right"></div>
</section>
<section class="index-recent-pages">
@if($result['entryCount'] != 0)
@foreach($result['pages'] as $page)
@php
$type = '';
$file = '';
isset($page['media'][0]['type']) ? $type = $page['media'][0]['type'] : $type = '';
isset($page['media'][0]['file']) ? $file = $page['media'][0]['file'] : $file = '';
@endphp
@if($type =='mp4')
<a href="/dashboard/page/edit/{{ $page['uuid'] }}" id="{{ $page['uuid'] }}" class="post-video-link recent-link">
@include('includes.recent-meta')
<video class="post-video" loop muted autoplay>
<source src="{{ $file }}" type="video/mp4">
Sorry, your browser doesn't support embedded videos.
</video>
</a>
@else
<a href="/dashboard/page/edit/{{ $page['uuid'] }}" id="{{ $page['uuid'] }}" class="post-link recent-link" style="background: url({{ $file }}) no-repeat center center / cover #fc6399">
@include('includes.recent-meta')
</a>
@endif
@endforeach
@endif
</section>

View file

@ -1,8 +1,8 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\Dash\IndexController;
use App\Http\Controllers\Dash\AuthController;
/*
|--------------------------------------------------------------------------
@ -22,12 +22,13 @@ Route::get('/', function () {
//DASHBOARD
//login stuff
Route::get("/dashboard", [IndexController::class, 'login']);
Route::post("/login", [AuthController::class, 'enter']);
//back
Route::group(['prefix' => 'dashboard'], function () {
Route::get("/", [DashController::class, 'start']);
Route::get("/pages/{pageFilter?}/{pageNum?}", [DashController::class, 'book']);
Route::get("/page/{mode}/{uuid}", [DashController::class, 'page']);
Route::group(['prefix' => 'dashboard', 'middleware' => 'member.check'], function () {
Route::get("/start", [IndexController::class, 'start'])->name('start');
Route::get("/pages/{pageFilter?}/{pageNum?}", [IndexController::class, 'book']);
Route::get("/page/{mode}/{uuid}", [IndexController::class, 'page']);
Route::get("/logout", [AuthController::class, 'exit']);
});