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 Illuminate\Support\Facades\Auth;
use App\Repositories\LocationRepository; use App\Repositories\LocationRepository;
use App\Repositories\SourceRepository; use App\Repositories\SourceRepository;
use App\Repositories\MemberRepository;
use App\Services\PaginationService; use App\Services\PaginationService;
class FrontIndexController extends Controller class FrontIndexController extends Controller
{ {
protected $location; protected $location;
protected $source; protected $source;
protected $member;
protected $pagination; protected $pagination;
public function __construct( public function __construct(
LocationRepository $locationRepository, LocationRepository $locationRepository,
SourceRepository $sourceRepository, SourceRepository $sourceRepository,
MemberRepository $memberRepository,
PaginationService $paginationService PaginationService $paginationService
) { ) {
$this->location = $locationRepository; $this->location = $locationRepository;
$this->source = $sourceRepository; $this->source = $sourceRepository;
$this->member = $memberRepository;
$this->pagination = $paginationService; $this->pagination = $paginationService;
} }
public function start() 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 //for fresh installs that dont have any source data yet
$latest_update = 'Never Run'; $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'); $latest_update = $this->location->getRecent()[0]->updated_at->format('Y M d');
} }
return view('front.index', [ return view('front.index', [
@ -40,6 +49,7 @@ class FrontIndexController extends Controller
'title' => "The Bad Space" 'title' => "The Bad Space"
]); ]);
} }
}
public function indexSearch(Request $request) 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.']); 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) public function add($request)
{ {
$password = []; $password = [];
$newFriend = [];
if ($request->fresh_pass === $request->fresh_pass_confirm) { if ($request->fresh_pass === $request->fresh_pass_confirm) {
$password = Hash::make($request->fresh_pass); $password = Hash::make($request->fresh_pass);
} else { } else {
return ['status' => false, 'message' => "Passwords Do Not Match"]; 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([ $newFriend = $this->model::create([
'uuid' => Uuid::uuid4(), 'uuid' => Uuid::uuid4(),
'avatar' => 'default-member-avatar', 'avatar' => 'default-member-avatar',
@ -79,6 +82,21 @@ class MemberRepository
'created_at' => Carbon::now(), 'created_at' => Carbon::now(),
'last_login' => 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) { if ($newFriend) {
return ['status' => true, 'message' => "New Friend Made!"]; return ['status' => true, 'message' => "New Friend Made!"];

View File

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

View File

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

View File

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