forked from projects/thebadspace
added member create ui
now that editing member work, that process needed to be fleshed out by adding an admin method to add new members as well. now new members can be added by an admin also changed the name of a blade file that wasn't following the template naming convention
This commit is contained in:
parent
d0c8def297
commit
3c0762344e
7 changed files with 118 additions and 14 deletions
|
@ -62,6 +62,13 @@ class MemberController extends Controller
|
||||||
'title' => "Edit Member Info"]);
|
'title' => "Edit Member Info"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createMember(Request $Request)
|
||||||
|
{
|
||||||
|
return view('back.member', [
|
||||||
|
'mode' => 'member-create',
|
||||||
|
'title' => "Make a new friend"]);
|
||||||
|
}
|
||||||
|
|
||||||
//actions
|
//actions
|
||||||
public function profileEdit(Request $request)
|
public function profileEdit(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -84,4 +91,15 @@ class MemberController extends Controller
|
||||||
return back()->withErrors([$response['message']]);
|
return back()->withErrors([$response['message']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function memberCreate(Request $request)
|
||||||
|
{
|
||||||
|
$token = csrf_token();
|
||||||
|
$response = $this->member->add($request);
|
||||||
|
if ($response['status'] == true) {
|
||||||
|
return redirect('/den/member')->with('message', $response['message']);
|
||||||
|
} else {
|
||||||
|
return back()->withErrors([$response['message']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,20 @@ class Member extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
protected $table = "member";
|
protected $table = "member";
|
||||||
protected $fillable = ["uuid", "handle", "email", "password", "active", "role", "avatar", "pronoun", "gender"];
|
protected $primaryKey = 'id';
|
||||||
|
public $incrementing = true;
|
||||||
|
protected $fillable = [
|
||||||
|
"uuid",
|
||||||
|
"handle",
|
||||||
|
"email",
|
||||||
|
"password",
|
||||||
|
"active",
|
||||||
|
"role",
|
||||||
|
"avatar",
|
||||||
|
"pronoun",
|
||||||
|
"created_at",
|
||||||
|
"last_login"
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ namespace App\Repositories;
|
||||||
|
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class MemberRepository
|
class MemberRepository
|
||||||
{
|
{
|
||||||
|
@ -56,6 +58,35 @@ class MemberRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add($request)
|
||||||
|
{
|
||||||
|
$password = [];
|
||||||
|
if ($request->fresh_pass === $request->fresh_pass_confirm) {
|
||||||
|
$password = Hash::make($request->fresh_pass);
|
||||||
|
} else {
|
||||||
|
return ['status' => false, 'message' => "Passwords Do Not Match"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newFriend = $this->model::create([
|
||||||
|
'uuid' => Uuid::uuid4(),
|
||||||
|
'avatar' => 'default-member-avatar',
|
||||||
|
'handle' => $request->handle,
|
||||||
|
'email' => $request->email,
|
||||||
|
'pronoun' => $request->pronouns,
|
||||||
|
'role' => $request->role,
|
||||||
|
'active' => $request->status,
|
||||||
|
'password' => $password,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'last_login' => Carbon::now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($newFriend) {
|
||||||
|
return ['status' => true, 'message' => "New Friend Made!"];
|
||||||
|
} else {
|
||||||
|
return ['status' => false, 'message' => "Uh oh, New Friend Delay!"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function editProfile($request)
|
public function editProfile($request)
|
||||||
{
|
{
|
||||||
//get member to edit
|
//get member to edit
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
@section('title', 'Den | Member Admin')
|
@section('title', 'Den | Member Admin')
|
||||||
|
|
||||||
|
@php
|
||||||
|
if($mode == 'member-create')
|
||||||
|
{
|
||||||
|
$action_url = '/den/member/create';
|
||||||
|
}else{
|
||||||
|
$action_url = '/den/member/edit';
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
@section('main-content')
|
@section('main-content')
|
||||||
<section>
|
<section>
|
||||||
<article>
|
<article>
|
||||||
|
@ -13,7 +21,9 @@
|
||||||
@break
|
@break
|
||||||
|
|
||||||
@case('member-create')
|
@case('member-create')
|
||||||
Second case...
|
<h2>New Member Info</h2>
|
||||||
|
@include('forms.member-edit')
|
||||||
|
<br />
|
||||||
@break
|
@break
|
||||||
|
|
||||||
@default
|
@default
|
||||||
|
@ -21,6 +31,8 @@
|
||||||
@foreach($members as $member)
|
@foreach($members as $member)
|
||||||
<a href="/den/member/{{$member->uuid}}">{{$member->handle}}</a><br />
|
<a href="/den/member/{{$member->uuid}}">{{$member->handle}}</a><br />
|
||||||
@endforeach
|
@endforeach
|
||||||
|
<h2>Add Member </h2>
|
||||||
|
<a href="/den/member/edit/create">Make a new friend</a><br />
|
||||||
@endswitch
|
@endswitch
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -1,34 +1,61 @@
|
||||||
<form action="/den/member/edit" method="post" enctype="multipart/form-data">
|
<form action="{{$action_url}}" method="post" enctype="multipart/form-data">
|
||||||
<div>
|
<div>
|
||||||
<img class="your-avatar" src='{{$avatar}}'>
|
@php
|
||||||
|
isset($avatar) ? $avi = $avatar : $avi = '';
|
||||||
|
@endphp
|
||||||
|
<img class="your-avatar" src='{{$avi}}'>
|
||||||
<br />
|
<br />
|
||||||
<label>Handle</label><br />
|
<label>Handle</label><br />
|
||||||
<input type="text" name="handle" value="{{$member->handle}}" />
|
@php
|
||||||
|
isset($member->handle) ? $handle = $member->handle : $handle = '';
|
||||||
|
@endphp
|
||||||
|
<input type="text" name="handle" value="{{$handle}}" />
|
||||||
<br />
|
<br />
|
||||||
|
@php
|
||||||
|
isset($member->email) ? $email = $member->email : $email = '';
|
||||||
|
@endphp
|
||||||
<label>Email</label><br />
|
<label>Email</label><br />
|
||||||
<input type="text" name="email" value="{{$member->email}}" />
|
<input type="text" name="email" value="{{$email}}" />
|
||||||
<br />
|
<br />
|
||||||
|
@php
|
||||||
|
isset($member->pronoun) ? $pronoun = $member->pronoun : $pronoun = '';
|
||||||
|
@endphp
|
||||||
<label>Pronouns</label><br />
|
<label>Pronouns</label><br />
|
||||||
<input type="text" name="pronouns" value="{{$member->pronoun}}" />
|
<input type="text" name="pronouns" value="{{$pronoun}}" />
|
||||||
<br />
|
<br />
|
||||||
|
@php
|
||||||
|
isset($member->role) ? $role = $member->role : $role = 2;
|
||||||
|
@endphp
|
||||||
<label>Role</label><br />
|
<label>Role</label><br />
|
||||||
<input type="text" name="role" value="{{$member->role}}" />
|
<input type="text" name="role" value="{{$role}}" />
|
||||||
<br />
|
<br />
|
||||||
|
@if($mode == 'member-create')
|
||||||
|
<label>Fresh Password</label><br />
|
||||||
|
<input type="password" id="fresh_pass" name="fresh_pass" value="" />
|
||||||
|
<br />
|
||||||
|
<label>Confirm Fresh Password</label><br />
|
||||||
|
<input type="password" id="fresh_pass_confirm" name="fresh_pass_confirm" value="" />
|
||||||
|
<br />
|
||||||
|
@endif
|
||||||
|
@php
|
||||||
|
isset($member->active) ? $status = $member->active : $status = false;
|
||||||
|
@endphp
|
||||||
<label>Status</label><br />
|
<label>Status</label><br />
|
||||||
<select name="status">
|
<select name="status">
|
||||||
@if($member->active == true)
|
@if($status)
|
||||||
<option value="true" selected>Active</option>
|
<option value="true" selected>Active</option>
|
||||||
<option value="false">Not Active</option>
|
<option value="false">Not Active</option>
|
||||||
@else
|
@else
|
||||||
<option value="true">Active</option>
|
<option value="true">Active</option>
|
||||||
<option value="false" selected>Not Active</option>
|
<option value="false" selected>Not Active</option>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
@csrf
|
@csrf
|
||||||
<input type="hidden" name="id" value="{{$member->uuid}}" />
|
@php
|
||||||
|
isset($member->uuid) ? $uuid = $member->uuid : $uuid = 0;
|
||||||
|
@endphp
|
||||||
|
<input type="hidden" name="id" value="{{$uuid}}" />
|
||||||
<input type="submit" value="Edit Member" name="submit_button">
|
<input type="submit" value="Edit Member" name="submit_button">
|
||||||
</form>
|
</form>
|
|
@ -52,6 +52,9 @@ Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () {
|
||||||
Route::get("/you", [MemberController::class, 'profile']);
|
Route::get("/you", [MemberController::class, 'profile']);
|
||||||
Route::get("/member", [MemberController::class, 'index']);
|
Route::get("/member", [MemberController::class, 'index']);
|
||||||
Route::get("/member/{uuid}", [MemberController::class, 'editMember']);
|
Route::get("/member/{uuid}", [MemberController::class, 'editMember']);
|
||||||
|
Route::get("/member/edit/create", [MemberController::class, 'createMember']);
|
||||||
|
//actions
|
||||||
Route::post("/profile/edit", [MemberController::class, 'profileEdit']);
|
Route::post("/profile/edit", [MemberController::class, 'profileEdit']);
|
||||||
Route::post("/member/edit", [MemberController::class, 'memberEdit']);
|
Route::post("/member/edit", [MemberController::class, 'memberEdit']);
|
||||||
|
Route::post("/member/create", [MemberController::class, 'memberCreate']);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue