1
0
mirror of https://koodu.h-i.works/projects/thebadspace synced 2025-05-06 14:41:02 -05:00

admin account set up

after the site is installed and the DB set up, there needed to be a way
to create the first account that will be used as the admin to access the
den, the admin section of tbs

the system makes a check to see if this account exists and if there
isn't one present, it shows the admin account set up screen on the
index. it goes away after the account is created.
This commit is contained in:
ro 2025-04-17 17:14:15 -06:00
parent 8e9ce4dd45
commit a5c3bf7178
6 changed files with 194 additions and 111 deletions

View File

@ -6,30 +6,39 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Repositories\LocationRepository;
use App\Repositories\SourceRepository;
use App\Repositories\MemberRepository;
use App\Services\PaginationService;
class FrontIndexController extends Controller
{
protected $location;
protected $source;
protected $member;
protected $pagination;
public function __construct(
LocationRepository $locationRepository,
SourceRepository $sourceRepository,
MemberRepository $memberRepository,
PaginationService $paginationService
) {
$this->location = $locationRepository;
$this->source = $sourceRepository;
$this->member = $memberRepository;
$this->pagination = $paginationService;
}
public function start()
{
//check to see if there are any accounts
if (count($this->member->getAll()) == 0) {
return view('back.member', [
'mode' => 'admin-create',
'title' => "Welcome, welcome"]);
} else {
//for fresh installs that dont have any source data yet
$latest_update = 'Never Run';
if(count($this->location->getRecent()) != 0)
{
if (count($this->location->getRecent()) != 0) {
$latest_update = $this->location->getRecent()[0]->updated_at->format('Y M d');
}
return view('front.index', [
@ -40,6 +49,7 @@ class FrontIndexController extends Controller
'title' => "The Bad Space"
]);
}
}
public function indexSearch(Request $request)
{

View File

@ -151,4 +151,32 @@ class MemberController extends Controller
return back()->withErrors(['Nah, you can\'t do this. Wrong permissions.']);
}
}
public function adminCreate(Request $request)
{
//should only be run of no members exist
if (count($this->member->getAll()) == 0) {
$token = csrf_token();
$valid = $request->validate([
'handle' => ['required'],
'email' => ['required'],
'pronouns' => ['required'],
'fresh_pass' => ['required'],
'fresh_pass_confirm' => ['required'],
]);
if ($valid) {
$response = $this->member->add($request);
if ($response['status'] == true) {
return redirect('/den/member')->with('message', $response['message']);
} else {
return back()->withErrors([$response['message']]);
}
} else {
return back()->withErrors(['Misssing some required info, homie.']);
}
} else {
return back()->withErrors(['Shame on you for even trying that.']);
}
}
}

View File

@ -61,12 +61,15 @@ class MemberRepository
public function add($request)
{
$password = [];
$newFriend = [];
if ($request->fresh_pass === $request->fresh_pass_confirm) {
$password = Hash::make($request->fresh_pass);
} else {
return ['status' => false, 'message' => "Passwords Do Not Match"];
}
//if role paramter is set, not an admin add
if (isset($request->role)) {
$newFriend = $this->model::create([
'uuid' => Uuid::uuid4(),
'avatar' => 'default-member-avatar',
@ -79,6 +82,21 @@ class MemberRepository
'created_at' => Carbon::now(),
'last_login' => Carbon::now(),
]);
} else {
//set up admin
$newFriend = $this->model::create([
'uuid' => Uuid::uuid4(),
'avatar' => 'default-member-avatar',
'handle' => $request->handle,
'email' => $request->email,
'pronoun' => $request->pronouns,
'role' => 0,
'active' => true,
'password' => $password,
'created_at' => Carbon::now(),
'last_login' => Carbon::now(),
]);
}
if ($newFriend) {
return ['status' => true, 'message' => "New Friend Made!"];

View File

@ -3,11 +3,17 @@
@section('title', 'Den | Member Admin')
@php
if($mode == 'member-create')
switch($mode)
{
case 'member-create':
$action_url = '/den/member/create';
}else{
break;
case 'member-edit':
$action_url = '/den/member/edit';
break;
case 'admin-create':
$action_url = '/den/member/admin-create';
break;
}
@endphp
@section('main-content')
@ -26,6 +32,13 @@
<br />
@break
@case('admin-create')
<h2>Make your first account</h2>
*This will be your administrator account.
@include('forms.member-edit')
<br />
@break
@default
<h2>Member Listing </h2>
@foreach($members as $member)

View File

@ -25,11 +25,20 @@
<br />
@php
isset($member->role) ? $role = $member->role : $role = 2;
//for creation of initial admin account
if($mode == 'admin-create')
{
$role = 0;
}
@endphp
@if($mode != 'admin-create')
<label>Role</label><br />
<input type="text" name="role" value="{{$role}}" />
<br />
@if($mode == 'member-create')
@endif
@if($mode == 'member-create' || $mode == 'admin-create')
<label>Fresh Password</label><br />
<input type="password" id="fresh_pass" name="fresh_pass" value="" />
<br />
@ -40,6 +49,8 @@
@php
isset($member->active) ? $status = $member->active : $status = false;
@endphp
@if($mode != 'admin-create')
<label>Status</label><br />
<select name="status">
@if($status)
@ -51,6 +62,8 @@
@endif
</select>
<br />
@endif
</div>
@csrf
@php

View File

@ -28,6 +28,7 @@ Route::get("/location/{uuid}", [FrontIndexController::class, 'location']);
Route::get("/appeals", [FrontIndexController::class, 'appeals']);
Route::post("/search", [FrontIndexController::class, 'indexSearch']);
Route::post("/appeal", [AppealController::class, 'sendAppeal']);
Route::post("/den/member/admin-create", [MemberController::class, 'adminCreate']);
//exports
Route::get("/exports", [ExportController::class, 'exportIndex']);