diff --git a/app/Http/Controllers/MemberController.php b/app/Http/Controllers/MemberController.php index 741a644..50db498 100644 --- a/app/Http/Controllers/MemberController.php +++ b/app/Http/Controllers/MemberController.php @@ -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']]); + } + } } diff --git a/app/Models/Member.php b/app/Models/Member.php index f4397d6..9ebe01d 100644 --- a/app/Models/Member.php +++ b/app/Models/Member.php @@ -9,7 +9,20 @@ class Member extends Authenticatable { use HasFactory; - public $timestamps = false; - protected $table = "member"; - protected $fillable = ["uuid", "handle", "email", "password", "active", "role", "avatar", "pronoun", "gender"]; + public $timestamps = false; + protected $table = "member"; + protected $primaryKey = 'id'; + public $incrementing = true; + protected $fillable = [ + "uuid", + "handle", + "email", + "password", + "active", + "role", + "avatar", + "pronoun", + "created_at", + "last_login" + ]; } diff --git a/app/Repositories/MemberRepository.php b/app/Repositories/MemberRepository.php index 8ff8006..bbb7305 100644 --- a/app/Repositories/MemberRepository.php +++ b/app/Repositories/MemberRepository.php @@ -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 diff --git a/resources/views/back/listings.php b/resources/views/back/listings.blade.php similarity index 100% rename from resources/views/back/listings.php rename to resources/views/back/listings.blade.php diff --git a/resources/views/back/member.blade.php b/resources/views/back/member.blade.php index e2af712..1f3b1de 100644 --- a/resources/views/back/member.blade.php +++ b/resources/views/back/member.blade.php @@ -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')
@@ -13,7 +21,9 @@ @break @case('member-create') - Second case... +

New Member Info

+ @include('forms.member-edit') +
@break @default @@ -21,6 +31,8 @@ @foreach($members as $member) {{$member->handle}}
@endforeach +

Add Member

+ Make a new friend
@endswitch
diff --git a/resources/views/forms/member-edit.blade.php b/resources/views/forms/member-edit.blade.php index f4d9f3f..3d8c7c2 100644 --- a/resources/views/forms/member-edit.blade.php +++ b/resources/views/forms/member-edit.blade.php @@ -1,34 +1,61 @@ -
+
- + @php + isset($avatar) ? $avi = $avatar : $avi = ''; + @endphp +

- + @php + isset($member->handle) ? $handle = $member->handle : $handle = ''; + @endphp +
+ @php + isset($member->email) ? $email = $member->email : $email = ''; + @endphp
- +
+ @php + isset($member->pronoun) ? $pronoun = $member->pronoun : $pronoun = ''; + @endphp
- +
+ @php + isset($member->role) ? $role = $member->role : $role = 2; + @endphp
- +
+ @if($mode == 'member-create') +
+ +
+
+ +
+ @endif + @php + isset($member->active) ? $status = $member->active : $status = false; + @endphp

@csrf - + @php + isset($member->uuid) ? $uuid = $member->uuid : $uuid = 0; + @endphp +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 94cd030..9c65116 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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']); });