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
This commit is contained in:
parent
99e22f5697
commit
d0c8def297
9 changed files with 160 additions and 39 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -46,4 +46,5 @@ select {
|
|||
appearance: none;
|
||||
color: var(--primary);
|
||||
background: var(--secondary);
|
||||
height: 35px;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,23 @@
|
|||
@section('main-content')
|
||||
<section>
|
||||
<article>
|
||||
<h2>Member Listing </h2>
|
||||
@switch($mode)
|
||||
@case('member-edit')
|
||||
<h2>Edit Info for {{$member->handle}}</h2>
|
||||
@include('forms.member-edit')
|
||||
<br />
|
||||
@break
|
||||
|
||||
@case('member-create')
|
||||
Second case...
|
||||
@break
|
||||
|
||||
@default
|
||||
<h2>Member Listing </h2>
|
||||
@foreach($members as $member)
|
||||
<a href="/den/member/{{$member->uuid}}">{{$member->handle}}</a><br />
|
||||
@endforeach
|
||||
@endswitch
|
||||
</article>
|
||||
</section>
|
||||
@endsection
|
|
@ -8,8 +8,8 @@
|
|||
<article>
|
||||
<h2>Hey {{$handle}} </h2>
|
||||
<a href="/den/you">Edit Your Account</a><br />
|
||||
<a href="/den/locations">Manage Locations</a><br />
|
||||
@if($role==1)
|
||||
@if($role==0)
|
||||
<a href="/den/locations">Manage Locations</a><br />
|
||||
<a href="/den/member">Manage Members</a><br />
|
||||
@endif
|
||||
</article>
|
||||
|
|
34
resources/views/forms/member-edit.blade.php
Normal file
34
resources/views/forms/member-edit.blade.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<form action="/den/member/edit" method="post" enctype="multipart/form-data">
|
||||
<div>
|
||||
<img class="your-avatar" src='{{$avatar}}'>
|
||||
<br />
|
||||
<label>Handle</label><br />
|
||||
<input type="text" name="handle" value="{{$member->handle}}" />
|
||||
<br />
|
||||
<label>Email</label><br />
|
||||
<input type="text" name="email" value="{{$member->email}}" />
|
||||
<br />
|
||||
<label>Pronouns</label><br />
|
||||
<input type="text" name="pronouns" value="{{$member->pronoun}}" />
|
||||
<br />
|
||||
<label>Role</label><br />
|
||||
<input type="text" name="role" value="{{$member->role}}" />
|
||||
<br />
|
||||
<label>Status</label><br />
|
||||
<select name="status">
|
||||
@if($member->active == true)
|
||||
<option value="true" selected>Active</option>
|
||||
<option value="false">Not Active</option>
|
||||
@else
|
||||
<option value="true">Active</option>
|
||||
<option value="false" selected>Not Active</option>
|
||||
@endif
|
||||
|
||||
|
||||
</select>
|
||||
<br />
|
||||
</div>
|
||||
@csrf
|
||||
<input type="hidden" name="id" value="{{$member->uuid}}" />
|
||||
<input type="submit" value="Edit Member" name="submit_button">
|
||||
</form>
|
|
@ -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']);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue