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"]);
|
||||
}
|
||||
|
||||
public function createMember(Request $Request)
|
||||
{
|
||||
return view('back.member', [
|
||||
'mode' => 'member-create',
|
||||
'title' => "Make a new friend"]);
|
||||
}
|
||||
|
||||
//actions
|
||||
public function profileEdit(Request $request)
|
||||
{
|
||||
|
@ -84,4 +91,15 @@ class MemberController extends Controller
|
|||
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']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,18 @@ class Member extends Authenticatable
|
|||
|
||||
public $timestamps = false;
|
||||
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 Illuminate\Support\Facades\Hash;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Carbon\Carbon;
|
||||
|
||||
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)
|
||||
{
|
||||
//get member to edit
|
||||
|
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
@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>
|
||||
<article>
|
||||
|
@ -13,7 +21,9 @@
|
|||
@break
|
||||
|
||||
@case('member-create')
|
||||
Second case...
|
||||
<h2>New Member Info</h2>
|
||||
@include('forms.member-edit')
|
||||
<br />
|
||||
@break
|
||||
|
||||
@default
|
||||
|
@ -21,6 +31,8 @@
|
|||
@foreach($members as $member)
|
||||
<a href="/den/member/{{$member->uuid}}">{{$member->handle}}</a><br />
|
||||
@endforeach
|
||||
<h2>Add Member </h2>
|
||||
<a href="/den/member/edit/create">Make a new friend</a><br />
|
||||
@endswitch
|
||||
</article>
|
||||
</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>
|
||||
<img class="your-avatar" src='{{$avatar}}'>
|
||||
@php
|
||||
isset($avatar) ? $avi = $avatar : $avi = '';
|
||||
@endphp
|
||||
<img class="your-avatar" src='{{$avi}}'>
|
||||
<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 />
|
||||
@php
|
||||
isset($member->email) ? $email = $member->email : $email = '';
|
||||
@endphp
|
||||
<label>Email</label><br />
|
||||
<input type="text" name="email" value="{{$member->email}}" />
|
||||
<input type="text" name="email" value="{{$email}}" />
|
||||
<br />
|
||||
@php
|
||||
isset($member->pronoun) ? $pronoun = $member->pronoun : $pronoun = '';
|
||||
@endphp
|
||||
<label>Pronouns</label><br />
|
||||
<input type="text" name="pronouns" value="{{$member->pronoun}}" />
|
||||
<input type="text" name="pronouns" value="{{$pronoun}}" />
|
||||
<br />
|
||||
@php
|
||||
isset($member->role) ? $role = $member->role : $role = 2;
|
||||
@endphp
|
||||
<label>Role</label><br />
|
||||
<input type="text" name="role" value="{{$member->role}}" />
|
||||
<input type="text" name="role" value="{{$role}}" />
|
||||
<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 />
|
||||
<select name="status">
|
||||
@if($member->active == true)
|
||||
@if($status)
|
||||
<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}}" />
|
||||
@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">
|
||||
</form>
|
|
@ -52,6 +52,9 @@ Route::group(['prefix' => 'den', 'middleware' => 'member.check'], function () {
|
|||
Route::get("/you", [MemberController::class, 'profile']);
|
||||
Route::get("/member", [MemberController::class, 'index']);
|
||||
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("/member/edit", [MemberController::class, 'memberEdit']);
|
||||
Route::post("/member/create", [MemberController::class, 'memberCreate']);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue