From d0c8def29735aff67f509148397572cd7b4f5bd1 Mon Sep 17 00:00:00 2001 From: ro Date: Tue, 24 Sep 2024 16:21:59 -0600 Subject: [PATCH] added member edit admin ui needed way to edit existing members info if needed, so simple ui was created for admins of the site to change specific info, not including a members avi or password. also consolidated memeber action and ui into it's own controller for the sake of clearer organization --- app/Http/Controllers/DenController.php | 28 -------- app/Http/Controllers/FrontIndexController.php | 2 +- app/Http/Controllers/MemberController.php | 65 ++++++++++++++++++- app/Repositories/MemberRepository.php | 37 +++++++++++ public/assets/css/global/forms.css | 1 + resources/views/back/member.blade.php | 18 ++++- resources/views/back/start.blade.php | 4 +- resources/views/forms/member-edit.blade.php | 34 ++++++++++ routes/web.php | 10 +-- 9 files changed, 160 insertions(+), 39 deletions(-) create mode 100644 resources/views/forms/member-edit.blade.php diff --git a/app/Http/Controllers/DenController.php b/app/Http/Controllers/DenController.php index ce9c672..2c11ee5 100644 --- a/app/Http/Controllers/DenController.php +++ b/app/Http/Controllers/DenController.php @@ -34,34 +34,6 @@ class DenController extends Controller ]); } - public function profile(Request $request) - { - $member = Auth::user(); - $avi = ''; - if ($member->avatar == 'default-member-avatar') { - $avi = '/assets/images/global/default-avi.png'; - } else { - $avi = $member->avatar; - } - return view('back.profile', [ - 'title' => "Your Profile", - 'handle' => $member->handle, - 'email' => $member->email, - 'avatar' => $avi, - 'pronouns' => $member->pronoun, - 'uuid' => $member->uuid, - 'role' => $member->role - ]); - } - - public function member(Request $request) - { - $member = Auth::user(); - return view('back.member', [ - 'handle' => $member->handle, - 'title' => "Manage Members"]); - } - public function locations(Request $request) { $member = Auth::user(); diff --git a/app/Http/Controllers/FrontIndexController.php b/app/Http/Controllers/FrontIndexController.php index 7852020..ce6409d 100644 --- a/app/Http/Controllers/FrontIndexController.php +++ b/app/Http/Controllers/FrontIndexController.php @@ -76,7 +76,7 @@ class FrontIndexController extends Controller } if (isset($member->role)) { - ($member->role == 1 || $member->role == 2) ? $edit = true : $edit = false; + ($member->role == 0 || $member->role == 1) ? $edit = true : $edit = false; } $links = explode(',', $location->archive_links); diff --git a/app/Http/Controllers/MemberController.php b/app/Http/Controllers/MemberController.php index c685b71..741a644 100644 --- a/app/Http/Controllers/MemberController.php +++ b/app/Http/Controllers/MemberController.php @@ -3,22 +3,81 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use App\Repositories\MemberRepository; class MemberController extends Controller { - protected $members; + protected $member; public function __construct( MemberRepository $memberRepo ) { - $this->members = $memberRepo; + $this->member = $memberRepo; + } + + public function index(Request $request) + { + $member = Auth::user(); + return view('back.member', [ + 'handle' => $member->handle, + 'members' => $this->member->getAll(), + 'mode' => 'index', + 'title' => "Manage Members"]); + } + + public function profile(Request $request) + { + $member = Auth::user(); + $avi = ''; + if ($member->avatar == 'default-member-avatar') { + $avi = '/assets/images/global/default-avi.png'; + } else { + $avi = $member->avatar; + } + return view('back.profile', [ + 'title' => "Hey, it's you!", + 'handle' => $member->handle, + 'email' => $member->email, + 'avatar' => $avi, + 'pronouns' => $member->pronoun, + 'uuid' => $member->uuid, + 'role' => $member->role + ]); + } + + public function editMember(Request $request, $uuid = 0) + { + $member = $this->member->get($uuid); + $avi = ''; + if ($member->avatar == 'default-member-avatar') { + $avi = '/assets/images/global/default-avi.png'; + } else { + $avi = $member->avatar; + } + return view('back.member', [ + 'member' => $member, + 'avatar' => $avi, + 'mode' => 'member-edit', + 'title' => "Edit Member Info"]); + } + + //actions + public function profileEdit(Request $request) + { + $token = csrf_token(); + $response = $this->member->editProfile($request); + if ($response['status'] == true) { + return back()->with('message', $response['message']); + } else { + return back()->withErrors([$response['message']]); + } } public function memberEdit(Request $request) { $token = csrf_token(); - $response = $this->members->edit($request); + $response = $this->member->edit($request); if ($response['status'] == true) { return back()->with('message', $response['message']); } else { diff --git a/app/Repositories/MemberRepository.php b/app/Repositories/MemberRepository.php index ab1456c..8ff8006 100644 --- a/app/Repositories/MemberRepository.php +++ b/app/Repositories/MemberRepository.php @@ -14,6 +14,11 @@ class MemberRepository $this->model = $model; } + public function getAll() + { + return $this->model::all(); + } + public function get($uuid) { return $this->model::where("uuid", $uuid)->first(); @@ -24,6 +29,38 @@ class MemberRepository //get member to edit $member = $this->get($request->id); + //save new avi if available + $publicPath = '../public/'; + $refPath = 'assets/images/members/' . $member->uuid; + if ($request->hasfile("fresh_avi")) { + $file = $request->fresh_avi; + if (!is_dir($publicPath . $refPath)) { + mkdir($publicPath . $refPath, 0755, true); + } + $filename = urlencode($file->getClientOriginalName()); + $file->move($publicPath . $refPath, $filename); + $freshAvi = '/' . $refPath . '/' . $filename; + $member->avatar = $freshAvi; + } + + $member->handle = $request->handle; + $member->email = $request->email; + $member->pronoun = $request->pronouns; + $member->role = $request->role; + $member->active = $request->status; + + if ($member->save()) { + return ['status' => true, 'message' => "Member Editited"]; + } else { + return ['status' => false, 'message' => "Member Not Editited"]; + } + } + + public function editProfile($request) + { + //get member to edit + $member = $this->get($request->id); + //save new avi if available $publicPath = '../public/'; $refPath = 'assets/images/members/' . $member->uuid; diff --git a/public/assets/css/global/forms.css b/public/assets/css/global/forms.css index 17697ca..f965472 100644 --- a/public/assets/css/global/forms.css +++ b/public/assets/css/global/forms.css @@ -46,4 +46,5 @@ select { appearance: none; color: var(--primary); background: var(--secondary); + height: 35px; } diff --git a/resources/views/back/member.blade.php b/resources/views/back/member.blade.php index 3140d9b..e2af712 100644 --- a/resources/views/back/member.blade.php +++ b/resources/views/back/member.blade.php @@ -5,7 +5,23 @@ @section('main-content')
-

Member Listing

+ @switch($mode) + @case('member-edit') +

Edit Info for {{$member->handle}}

+ @include('forms.member-edit') +
+ @break + + @case('member-create') + Second case... + @break + + @default +

Member Listing

+ @foreach($members as $member) + {{$member->handle}}
+ @endforeach + @endswitch
@endsection \ No newline at end of file diff --git a/resources/views/back/start.blade.php b/resources/views/back/start.blade.php index 0d8bc13..0b33ca4 100644 --- a/resources/views/back/start.blade.php +++ b/resources/views/back/start.blade.php @@ -8,8 +8,8 @@

Hey {{$handle}}

Edit Your Account
- Manage Locations
- @if($role==1) + @if($role==0) + Manage Locations
Manage Members
@endif
diff --git a/resources/views/forms/member-edit.blade.php b/resources/views/forms/member-edit.blade.php new file mode 100644 index 0000000..f4d9f3f --- /dev/null +++ b/resources/views/forms/member-edit.blade.php @@ -0,0 +1,34 @@ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ @csrf + + +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index aaff243..94cd030 100644 --- a/routes/web.php +++ b/routes/web.php @@ -41,8 +41,6 @@ Route::get("/logout", [AuthController::class, 'leave']); //back Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () { Route::get("/", [DenController::class, 'start']); - Route::get("/you", [DenController::class, 'profile']); - Route::get("/member", [DenController::class, 'member']); Route::get("/listings/{pageNum}", [DenController::class, 'location']); Route::get("/location/edit/{uuid}", [DenController::class, 'locationEdit']); Route::get("/locations", [DenController::class, 'locations']); @@ -50,6 +48,10 @@ Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () { Route::post("/locations/edit", [LocationController::class, 'editLocation']); Route::get("/admin/update", [LocationController::class, 'updateLocations']); Route::get("/admin/compile", [LocationController::class, 'compileLocations']); - //member actions - Route::post("/profile/edit", [MemberController::class, 'memberEdit']); + //member stuff + Route::get("/you", [MemberController::class, 'profile']); + Route::get("/member", [MemberController::class, 'index']); + Route::get("/member/{uuid}", [MemberController::class, 'editMember']); + Route::post("/profile/edit", [MemberController::class, 'profileEdit']); + Route::post("/member/edit", [MemberController::class, 'memberEdit']); });