From 064407aa881fba650f84d2c969877bbb7d8f362c Mon Sep 17 00:00:00 2001 From: ro Date: Mon, 13 May 2024 12:06:05 -0600 Subject: [PATCH] implemented member repo class a class for members was needed for long term handling of member functions like login, update, status checking, etc so that class was created and the AuthService class was removed as it was redundant and it's functionaity moved to the member class --- .../Controllers/API/AuthAPIController.php | 10 ++-- .../Controllers/API/SettingsAPIController.php | 10 ++-- app/Http/Controllers/AuthController.php | 10 ++-- app/Http/Controllers/DashController.php | 20 +++---- app/Http/Controllers/FrontController.php | 4 -- app/Http/Controllers/RouteController.php | 20 +++---- app/Http/Controllers/ThemeController.php | 14 ++--- app/Interfaces/MemberRepositoryInterface.php | 22 ++++++++ app/Providers/FipamoServiceProvider.php | 8 +-- .../MemberRepository.php} | 55 ++++++++++++++++--- app/Services/Data/SettingsService.php | 13 ----- 11 files changed, 115 insertions(+), 71 deletions(-) create mode 100644 app/Interfaces/MemberRepositoryInterface.php rename app/{Services/Data/AuthService.php => Repositories/MemberRepository.php} (60%) diff --git a/app/Http/Controllers/API/AuthAPIController.php b/app/Http/Controllers/API/AuthAPIController.php index fb32d76..12c93e9 100644 --- a/app/Http/Controllers/API/AuthAPIController.php +++ b/app/Http/Controllers/API/AuthAPIController.php @@ -3,22 +3,24 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; -use App\Services\AuthService; +use App\Interfaces\MemberRepositoryInterface; use Illuminate\Http\Request; class AuthAPIController extends Controller { + protected $member; + public function __construct( - AuthService $authService + MemberRepositoryInterface $memberRepo ) { - $this->auth = $authService; + $this->member = $memberRepo; } public function status(Request $request) { $result = []; $data = json_decode($request->getContent()); - if ($this->auth::status()) { + if ($this->member::status()) { $result = [ 'message' => 'Authorized', 'type' => 'apiUseAuthorized', diff --git a/app/Http/Controllers/API/SettingsAPIController.php b/app/Http/Controllers/API/SettingsAPIController.php index 5496f7e..7c8c4cc 100644 --- a/app/Http/Controllers/API/SettingsAPIController.php +++ b/app/Http/Controllers/API/SettingsAPIController.php @@ -7,7 +7,7 @@ use Illuminate\Http\Request; use App\Services\SettingsService; use App\Services\RenderService; use App\Services\MaintenanceService; -use App\Services\AuthService; +use App\Interfaces\MemberRepositoryInterface; use App\Services\AssetService; class SettingsAPIController extends Controller @@ -15,20 +15,20 @@ class SettingsAPIController extends Controller protected $settings; protected $render; protected $mainteance; - protected $auth; + protected $member; protected $assets; public function __construct( SettingsService $settingsService, RenderService $renderService, MaintenanceService $maintenanceService, - AuthService $authService, + MemberRepositoryInterface $memberRepo, AssetService $assetService ) { $this->settings = $settingsService; $this->render = $renderService; $this->maintenance = $maintenanceService; - $this->auth = $authService; + $this->member = $memberRepo; $this->assets = $assetService; } @@ -60,7 +60,7 @@ class SettingsAPIController extends Controller public function downloadBackup(Request $request) { - if ($this->auth::status()) { + if ($this->member::status()) { $latest = $this->settings->getGlobal()['last_backup']; $file = 'backup-' . $latest . '.zip'; return response()->download('../content/backups/' . $file, $file, ['Content-Type: application/zip']); diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index e6565b8..94771c0 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -3,15 +3,17 @@ namespace App\Http\Controllers; use Symfony\Component\HttpFoundation\Response; -use App\Services\Data\AuthService; +use App\Interfaces\MemberRepositoryInterface; use Illuminate\Http\Request; class AuthController extends Controller { + protected $member; + public function __construct( - AuthService $authService + MemberRepositoryInterface $memberRepository ) { - $this->auth = $authService; + $this->member = $memberRepository; } public function enter(Request $request): Response @@ -24,7 +26,7 @@ class AuthController extends Controller ]); if ($credentials) { - $result = $this->auth->check($request); + $result = $this->member->auth($request); if ($result['status']) { //$request->session()->regenerate(); return redirect()->intended('dashboard/start'); diff --git a/app/Http/Controllers/DashController.php b/app/Http/Controllers/DashController.php index 94eaf1c..0dc99b0 100644 --- a/app/Http/Controllers/DashController.php +++ b/app/Http/Controllers/DashController.php @@ -3,25 +3,25 @@ namespace App\Http\Controllers; use App\Interfaces\PageRepositoryInterface; -use App\Services\Data\AuthService; +use App\Interfaces\MemberRepositoryInterface; use App\Services\Data\ThemeService; use App\Services\Data\SortingService; class DashController extends Controller { protected PageRepositoryInterface $pages; - protected AuthService $auth; + protected MemberRepositoryInterface $member; protected ThemeService $themes; protected SortingService $sort; public function __construct( PageRepositoryInterface $pageRepository, - AuthService $authService, + MemberRepositoryInterface $memberRepo, ThemeService $themeService, SortingService $sortingService ) { $this->pages = $pageRepository; - $this->auth = $authService; + $this->member = $memberRepo; $this->themes = $themeService; $this->sort = $sortingService; } @@ -54,11 +54,11 @@ class DashController extends Controller public function login() { - if ($this->auth::status()) { + if ($this->member::status()) { return redirect('dashboard'); } else { return view('back.login', [ - "status" => $this->auth::status(), + "status" => $this->member::status(), "title" => "Hi!" ]); } @@ -67,11 +67,11 @@ class DashController extends Controller public function start() { $result = []; - if ($this->auth::status()) { + if ($this->member::status()) { $result = $this->pages->getGroup(1, 4); } return view('back.start', [ - "status" => $this->auth::status(), + "status" => $this->member::status(), "result" => $result, "title" => "Start" ]); @@ -80,7 +80,7 @@ class DashController extends Controller public function book($pageFilter = 'all', $pageNum = 1) { $result = []; - if ($this->auth::status()) { + if ($this->member::status()) { $result = $this->pages->getGroup($pageNum, 4, $pageFilter); } return view('back.book', [ @@ -101,7 +101,7 @@ class DashController extends Controller $mode == 'edit' ? $views = $this->themes->getCustomViews($page['layout']) : $views[] = 'page'; return view('back.page', [ - "status" => $this->auth::status(), + "status" => $this->member::status(), "mode" => $mode, "page" => $page, "views" => $views, diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 6914cf8..f94c79a 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers; use App\Interfaces\PageRepositoryInterface; use App\Services\Assets\AssetService; use App\Services\Data\SettingsService; -use App\Services\Data\AuthService; use App\Services\Data\SortingService; use function _\find; @@ -13,7 +12,6 @@ use function _\find; class FrontController extends Controller { protected $settings; - protected $auth; protected PageRepositoryInterface $pages; protected AssetService $assets; protected SortingService $sort; @@ -21,13 +19,11 @@ class FrontController extends Controller public function __construct( PageRepositoryInterface $pageRepository, SettingsService $settingsService, - AuthService $authService, AssetService $assetService, SortingService $sortService, ) { $this->pages = $pageRepository; $this->settings = $settingsService; - $this->auth = $authService; $this->assets = $assetService; $this->sort = $sortService; } diff --git a/app/Http/Controllers/RouteController.php b/app/Http/Controllers/RouteController.php index fbe3f93..23b26f9 100644 --- a/app/Http/Controllers/RouteController.php +++ b/app/Http/Controllers/RouteController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Services\Data\AuthService; +use App\Interfaces\MemberRepositoryInterface; use Illuminate\Http\Request; class RouteController extends Controller @@ -11,20 +11,20 @@ class RouteController extends Controller protected $gate; protected $theme; protected $front; - protected $auth; + protected $member; public function __construct( DashController $dashController, AuthController $authController, ThemeController $themeController, FrontController $frontController, - AuthService $authService, + MemberRepositoryInterface $memberRepo, ) { - $this->dash = $dashController; - $this->gate = $authController; - $this->theme = $themeController; - $this->front = $frontController; - $this->auth = $authService; + $this->dash = $dashController; + $this->gate = $authController; + $this->theme = $themeController; + $this->front = $frontController; + $this->member = $memberRepo; } public function get($first = null, $second = null, $third = null, $fourth = null) @@ -32,14 +32,14 @@ class RouteController extends Controller if (isset($first) && !is_numeric($first)) { switch ($first) { case 'dashboard': - if ($this->auth::status()) { + if ($this->member::status()) { return $this->dash->init($second, $third, $fourth); } else { return $this->dash->login(); } break; case 'theme': - if ($this->auth::status()) { + if ($this->member::status()) { if (isset($second)) { return $this->theme->getView($third); } else { diff --git a/app/Http/Controllers/ThemeController.php b/app/Http/Controllers/ThemeController.php index 5524588..94d0e13 100644 --- a/app/Http/Controllers/ThemeController.php +++ b/app/Http/Controllers/ThemeController.php @@ -4,27 +4,27 @@ namespace App\Http\Controllers; use App\Interfaces\PageRepositoryInterface; use App\Services\Assets\AssetService; -use App\Services\Data\AuthService; +use App\Interfaces\MemberRepositoryInterface; use App\Services\Data\SortingService; use App\Services\Data\ThemeService; class ThemeController extends Controller { protected PageRepositoryInterface $pages; - protected AuthService $auth; + protected MemberRepositoryInterface $member; protected AssetService $assets; protected SortingService $sort; protected ThemeService $themes; public function __construct( PageRepositoryInterface $pageRepository, - AuthService $authService, + MemberRepositoryInterface $memberRepo, AssetService $assetService, SortingService $sortService, ThemeService $themeService, ) { $this->pages = $pageRepository; - $this->auth = $authService; + $this->member = $memberRepo; $this->assets = $assetService; $this->sort = $sortService; $this->themes = $themeService; @@ -32,9 +32,9 @@ class ThemeController extends Controller public function start() { - if ($this->auth::status()) { + if ($this->member::status()) { return view('theme.start', [ - "status" => $this->auth::status(), + "status" => $this->member::status(), "title" => "Fipamo Theme Kit", "pages" => $this->themes->getCustomViews('page') ]); @@ -73,7 +73,7 @@ class ThemeController extends Controller $page = $this->pages->getById('F4429D34-25E7-4CA9-9B0A-742810277505'); $pageData = $this->sort->page($page); } - if ($this->auth::status()) { + if ($this->member::status()) { return view($template, $pageData); } else { return redirect('dashboard/start'); diff --git a/app/Interfaces/MemberRepositoryInterface.php b/app/Interfaces/MemberRepositoryInterface.php new file mode 100644 index 0000000..5a8505f --- /dev/null +++ b/app/Interfaces/MemberRepositoryInterface.php @@ -0,0 +1,22 @@ +app->bind(AuthService::class, function ($app) { - return new AuthService(new SettingsService(new DocService(), new ContentService())); - }); - $this->app->bind(ContentService::class, function ($app) { return new ContentService(); }); @@ -103,5 +100,6 @@ class FipamoServiceProvider extends ServiceProvider public function boot(): void { $this->app->bind(PageRepositoryInterface::class, PageRepository::class); + $this->app->bind(MemberRepositoryInterface::class, MemberRepository::class); } } diff --git a/app/Services/Data/AuthService.php b/app/Repositories/MemberRepository.php similarity index 60% rename from app/Services/Data/AuthService.php rename to app/Repositories/MemberRepository.php index 4b6b30f..3a40fa7 100644 --- a/app/Services/Data/AuthService.php +++ b/app/Repositories/MemberRepository.php @@ -1,25 +1,62 @@ config = $config; + if (file_exists(env('FOLKS_PATH'))) { + $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); + } else { + $this->folks = json_decode(file_get_contents('../content/init/folks-template.json'), true); + } } - public function check($request) + public function getAll() { - $folks = $this->config->getFolks(); - $found = find($folks, ['handle' => $request->handle]); + return $this->$folks; + } + + public function getById($id) + { + $member = find($this->folks, ['id' => $id]); + return $member; + } + + public function getByHandle($handle) + { + $member = find($this->folks, ['handle' => $handle]); + return $member; + } + + public function delete($id) + { + //delete member stuff + } + + public function create($member) + { + //make new member + } + + public function update($id) + { + //update member data + } + + public function auth($request) + { + //suth stuff + $folks = $this->folks; + $found = $this->getByHandle($request->handle); if ($found) { if (password_verify($request->password, $found['password'])) { $member = [ diff --git a/app/Services/Data/SettingsService.php b/app/Services/Data/SettingsService.php index 6644a7a..8287402 100644 --- a/app/Services/Data/SettingsService.php +++ b/app/Services/Data/SettingsService.php @@ -10,20 +10,12 @@ use function _\find; class SettingsService { protected $settings; - protected $folks; protected $tags; protected $docs; protected $contents; public function __construct(DocService $docService, ContentService $contentService) { - //if config files aren't avaiable, load templates - if (file_exists(env('FOLKS_PATH'))) { - $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); - } else { - $this->folks = json_decode(file_get_contents('../content/init/folks-template.json'), true); - } - if (file_exists(env('TAGS_PATH'))) { $this->tags = json_decode(file_get_contents(env('TAGS_PATH')), true); } else { @@ -74,11 +66,6 @@ class SettingsService return $this->tags; } - public function getFolks() - { - return $this->folks; - } - public function updatePageIndex() { $this->settings = $this->loadSettings();