From 8c375e6ba1f2cebef0b3b26c428e9110379c571c Mon Sep 17 00:00:00 2001 From: ro Date: Mon, 13 May 2024 13:36:06 -0600 Subject: [PATCH] update member info from settings setting sync is working but member data was not being updated in the folks file or in the current active session, so that's been addressed still need to turn on avatar updating as well, but that is tied to updating the settings page, so that will be handled when image uploads for that area are reactivated --- .../Controllers/API/SettingsAPIController.php | 13 +++++++----- app/Interfaces/MemberRepositoryInterface.php | 2 +- app/Providers/FipamoServiceProvider.php | 4 ++-- app/Repositories/MemberRepository.php | 20 ++++++++++++++++--- app/Services/Data/SettingsService.php | 5 +++-- app/Services/Upkeep/MaintenanceService.php | 3 ++- .../dash/app/actions/SettingsActions.js | 7 ++++++- resources/views/back/settings.blade.php | 3 ++- 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/API/SettingsAPIController.php b/app/Http/Controllers/API/SettingsAPIController.php index 7c8c4cc..bf56e43 100644 --- a/app/Http/Controllers/API/SettingsAPIController.php +++ b/app/Http/Controllers/API/SettingsAPIController.php @@ -4,11 +4,11 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use App\Services\SettingsService; -use App\Services\RenderService; -use App\Services\MaintenanceService; +use App\Services\Data\SettingsService; +use App\Services\Assets\RenderService; +use App\Services\Upkeep\MaintenanceService; use App\Interfaces\MemberRepositoryInterface; -use App\Services\AssetService; +use App\Services\Assets\AssetService; class SettingsAPIController extends Controller { @@ -41,7 +41,10 @@ class SettingsAPIController extends Controller public function sync(Request $request) { - $body = json_decode($request->getContent()); + $body = json_decode($request->getContent()); + //update member if needed + $this->member->update($body->member); + //sync settings $result = $this->settings->sync($body); return response()->json($result)->header('Content-Type', 'application/json'); } diff --git a/app/Interfaces/MemberRepositoryInterface.php b/app/Interfaces/MemberRepositoryInterface.php index 5a8505f..b667926 100644 --- a/app/Interfaces/MemberRepositoryInterface.php +++ b/app/Interfaces/MemberRepositoryInterface.php @@ -14,7 +14,7 @@ interface MemberRepositoryInterface public function create($member); - public function update($id); + public function update($member); public function auth($request); diff --git a/app/Providers/FipamoServiceProvider.php b/app/Providers/FipamoServiceProvider.php index aee9976..b1c170b 100644 --- a/app/Providers/FipamoServiceProvider.php +++ b/app/Providers/FipamoServiceProvider.php @@ -20,8 +20,8 @@ use App\Services\Data\PaginateService; use App\Services\Data\ThemeService; use App\Services\Data\SortingService; //Upkeep Services -use App\Services\UpKeep\MaintenanceService; -use App\Services\UpKeep\InitService; +use App\Services\Upkeep\MaintenanceService; +use App\Services\Upkeep\InitService; class FipamoServiceProvider extends ServiceProvider { diff --git a/app/Repositories/MemberRepository.php b/app/Repositories/MemberRepository.php index 3a40fa7..fe511ab 100644 --- a/app/Repositories/MemberRepository.php +++ b/app/Repositories/MemberRepository.php @@ -2,17 +2,22 @@ namespace App\Repositories; +use App\Services\Assets\DocService; use App\Interfaces\MemberRepositoryInterface; use ReallySimpleJWT\Token; +use Carbon\Carbon; use function _\find; +use function _\findIndex; class MemberRepository implements MemberRepositoryInterface { protected $folks; + protected $docs; - public function __construct() + public function __construct(DocService $docService) { + $this->docs = $docService; if (file_exists(env('FOLKS_PATH'))) { $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); } else { @@ -47,9 +52,17 @@ class MemberRepository implements MemberRepositoryInterface //make new member } - public function update($id) + public function update($member) { - //update member data + //TODO: need to add member avatar updating + $index = findIndex($this->folks, ['id' => $member->id]); + $this->folks[$index]['handle'] = $member->handle; + $this->folks[$index]['email'] = $member->email; + $this->folks[$index]['updated'] = Carbon::now(); + //save new folks file + $this->docs::writeSettings($this->folks, env('FOLKS_PATH')); + //update session + session()->put('member', $this->folks[$index]); } public function auth($request) @@ -60,6 +73,7 @@ class MemberRepository implements MemberRepositoryInterface if ($found) { if (password_verify($request->password, $found['password'])) { $member = [ + 'id' => $found['id'], 'handle' => $found['handle'], 'email' => $found['email'], 'role' => $found['role'], diff --git a/app/Services/Data/SettingsService.php b/app/Services/Data/SettingsService.php index 8287402..f95c3f1 100644 --- a/app/Services/Data/SettingsService.php +++ b/app/Services/Data/SettingsService.php @@ -21,6 +21,8 @@ class SettingsService } else { $this->tags = []; } + + $this->docs = $docService; } protected function loadSettings() @@ -110,7 +112,6 @@ class SettingsService public function sync($data) { - //dd($data->global->renderOnSave); $settings = $this->getSettings(); $settings['global']['base_url'] = $data->global->base_url; $settings['global']['title'] = $data->global->title; @@ -129,7 +130,7 @@ class SettingsService $settings['email']['smtp'] = $data->email->smtp; $settings['email']['mailgun'] = $data->email->mailgun; - return $this->docs->writeSettings($settings); + return $this->docs::writeSettings($settings); } public function navSync($data) diff --git a/app/Services/Upkeep/MaintenanceService.php b/app/Services/Upkeep/MaintenanceService.php index 9534b16..af9f8f3 100644 --- a/app/Services/Upkeep/MaintenanceService.php +++ b/app/Services/Upkeep/MaintenanceService.php @@ -1,7 +1,8 @@
-
+
@@ -16,6 +16,7 @@
+