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
This commit is contained in:
ro 2024-05-13 13:36:06 -06:00
parent 064407aa88
commit 8c375e6ba1
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
8 changed files with 41 additions and 16 deletions

View file

@ -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');
}

View file

@ -14,7 +14,7 @@ interface MemberRepositoryInterface
public function create($member);
public function update($id);
public function update($member);
public function auth($request);

View file

@ -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
{

View file

@ -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'],

View file

@ -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)

View file

@ -1,7 +1,8 @@
<?php
namespace App\Services;
namespace App\Services\Upkeep;
use App\Services\Data\SettingsService;
use Carbon\Carbon;
class MaintenanceService

View file

@ -12,6 +12,7 @@ export default class SettingsActions {
let url = document.getElementById('settings-url').value;
let title = document.getElementById('settings-title').value;
let desc = document.getElementById('settings-desc').value;
let memberID = document.getElementById('member-id').value;
//let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
let render = document.getElementById('render-toggle').getAttribute('data-render');
let background = document
@ -55,7 +56,11 @@ export default class SettingsActions {
externalAPI: apiStatus,
dynamicRender: dynamicRenderStatus
},
member: { handle: handle, email: email },
member: {
handle: handle,
email: email,
id: memberID
},
email: {
active: mailActive,
smtp: {

View file

@ -6,7 +6,7 @@
<article class="settings">
<section class="member-settings">
<div class="member-avatar">
<div class="avatar" style="background: url({{ $member['avatar'] }} ) no-repeat center center / cover"></div>
<div class="avatar" style="background: url({{ $member['avi'] }} ) no-repeat center center / cover"></div>
<input id="avatar-upload" type="file" name="avatar-upload"/>
</div>
<div class="site-background">
@ -16,6 +16,7 @@
<div>
<input type='text' name='handle' id='settings-handle' placeholder='handle' value="{{ $member['handle'] }}" autofocus/>
<input type='text' name='email' id='settings-email' placeholder='email' value="{{ $member['email'] }}" autofocus/>
<input type='hidden' name='member-id' id='member-id' value="{{ $member['id'] }}"/>
<input type='text' name='base-url' id='settings-url' placeholder='url' value="{{ $baseUrl }}" autofocus/>
<input type='text' name='base-title' id='settings-title' placeholder='site title' value="{{ $siteTitle }}" autofocus/>
<textarea id="settings-desc" type='text' name='settings_desc' class='settings-dec' placeholder='description stuff' , autofocus>{{ $desc }}</textarea>