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:
parent
8e9ce4dd45
commit
a5c3bf7178
@ -6,39 +6,49 @@ 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()
|
||||||
{
|
{
|
||||||
//for fresh installs that dont have any source data yet
|
//check to see if there are any accounts
|
||||||
$latest_update = 'Never Run';
|
if (count($this->member->getAll()) == 0) {
|
||||||
if(count($this->location->getRecent()) != 0)
|
return view('back.member', [
|
||||||
{
|
'mode' => 'admin-create',
|
||||||
$latest_update = $this->location->getRecent()[0]->updated_at->format('Y M d');
|
'title' => "Welcome, welcome"]);
|
||||||
|
} else {
|
||||||
|
//for fresh installs that dont have any source data yet
|
||||||
|
$latest_update = 'Never Run';
|
||||||
|
if (count($this->location->getRecent()) != 0) {
|
||||||
|
$latest_update = $this->location->getRecent()[0]->updated_at->format('Y M d');
|
||||||
|
}
|
||||||
|
return view('front.index', [
|
||||||
|
'count' => count($this->location->getActiveLocations()),
|
||||||
|
'sources' => count($this->source->getActive()),
|
||||||
|
'recent' => $this->location->getRecent(),
|
||||||
|
'latest_date' => $latest_update,
|
||||||
|
'title' => "The Bad Space"
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
return view('front.index', [
|
|
||||||
'count' => count($this->location->getActiveLocations()),
|
|
||||||
'sources' => count($this->source->getActive()),
|
|
||||||
'recent' => $this->location->getRecent(),
|
|
||||||
'latest_date' => $latest_update,
|
|
||||||
'title' => "The Bad Space"
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexSearch(Request $request)
|
public function indexSearch(Request $request)
|
||||||
|
@ -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.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,25 +60,43 @@ 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"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$newFriend = $this->model::create([
|
//if role paramter is set, not an admin add
|
||||||
'uuid' => Uuid::uuid4(),
|
if (isset($request->role)) {
|
||||||
'avatar' => 'default-member-avatar',
|
$newFriend = $this->model::create([
|
||||||
'handle' => $request->handle,
|
'uuid' => Uuid::uuid4(),
|
||||||
'email' => $request->email,
|
'avatar' => 'default-member-avatar',
|
||||||
'pronoun' => $request->pronouns,
|
'handle' => $request->handle,
|
||||||
'role' => $request->role,
|
'email' => $request->email,
|
||||||
'active' => $request->status,
|
'pronoun' => $request->pronouns,
|
||||||
'password' => $password,
|
'role' => $request->role,
|
||||||
'created_at' => Carbon::now(),
|
'active' => $request->status,
|
||||||
'last_login' => Carbon::now(),
|
'password' => $password,
|
||||||
]);
|
'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) {
|
if ($newFriend) {
|
||||||
return ['status' => true, 'message' => "New Friend Made!"];
|
return ['status' => true, 'message' => "New Friend Made!"];
|
||||||
|
@ -2,38 +2,51 @@
|
|||||||
|
|
||||||
@section('title', 'Den | Member Admin')
|
@section('title', 'Den | Member Admin')
|
||||||
|
|
||||||
@php
|
@php
|
||||||
if($mode == 'member-create')
|
switch($mode)
|
||||||
{
|
{
|
||||||
$action_url = '/den/member/create';
|
case 'member-create':
|
||||||
}else{
|
$action_url = '/den/member/create';
|
||||||
$action_url = '/den/member/edit';
|
break;
|
||||||
}
|
case 'member-edit':
|
||||||
@endphp
|
$action_url = '/den/member/edit';
|
||||||
@section('main-content')
|
break;
|
||||||
<section>
|
case 'admin-create':
|
||||||
<article>
|
$action_url = '/den/member/admin-create';
|
||||||
@switch($mode)
|
break;
|
||||||
@case('member-edit')
|
}
|
||||||
<h2>Edit Info for {{$member->handle}}</h2>
|
@endphp
|
||||||
@include('forms.member-edit')
|
@section('main-content')
|
||||||
<br />
|
<section>
|
||||||
@break
|
<article>
|
||||||
|
@switch($mode)
|
||||||
|
@case('member-edit')
|
||||||
|
<h2>Edit Info for {{$member->handle}}</h2>
|
||||||
|
@include('forms.member-edit')
|
||||||
|
<br />
|
||||||
|
@break
|
||||||
|
|
||||||
@case('member-create')
|
@case('member-create')
|
||||||
<h2>New Member Info</h2>
|
<h2>New Member Info</h2>
|
||||||
@include('forms.member-edit')
|
@include('forms.member-edit')
|
||||||
<br />
|
<br />
|
||||||
@break
|
@break
|
||||||
|
|
||||||
@default
|
@case('admin-create')
|
||||||
<h2>Member Listing </h2>
|
<h2>Make your first account</h2>
|
||||||
@foreach($members as $member)
|
*This will be your administrator account.
|
||||||
<a href="/den/member/{{$member->uuid}}">{{$member->handle}}</a><br />
|
@include('forms.member-edit')
|
||||||
@endforeach
|
<br />
|
||||||
<h2>Add Member </h2>
|
@break
|
||||||
<a href="/den/member/edit/create">Make a new friend</a><br />
|
|
||||||
@endswitch
|
@default
|
||||||
</article>
|
<h2>Member Listing </h2>
|
||||||
</section>
|
@foreach($members as $member)
|
||||||
@endsection
|
<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>
|
||||||
|
@endsection
|
@ -1,61 +1,74 @@
|
|||||||
<form action="{{$action_url}}" method="post" enctype="multipart/form-data">
|
<form action="{{$action_url}}" method="post" enctype="multipart/form-data">
|
||||||
<div>
|
<div>
|
||||||
@php
|
@php
|
||||||
isset($avatar) ? $avi = $avatar : $avi = '';
|
isset($avatar) ? $avi = $avatar : $avi = '';
|
||||||
@endphp
|
@endphp
|
||||||
<img class="your-avatar" src='{{$avi}}'>
|
<img class="your-avatar" src='{{$avi}}'>
|
||||||
<br />
|
<br />
|
||||||
<label>Handle</label><br />
|
<label>Handle</label><br />
|
||||||
@php
|
@php
|
||||||
isset($member->handle) ? $handle = $member->handle : $handle = '';
|
isset($member->handle) ? $handle = $member->handle : $handle = '';
|
||||||
@endphp
|
@endphp
|
||||||
<input type="text" name="handle" value="{{$handle}}" />
|
<input type="text" name="handle" value="{{$handle}}" />
|
||||||
<br />
|
<br />
|
||||||
@php
|
@php
|
||||||
isset($member->email) ? $email = $member->email : $email = '';
|
isset($member->email) ? $email = $member->email : $email = '';
|
||||||
@endphp
|
@endphp
|
||||||
<label>Email</label><br />
|
<label>Email</label><br />
|
||||||
<input type="text" name="email" value="{{$email}}" />
|
<input type="text" name="email" value="{{$email}}" />
|
||||||
<br />
|
<br />
|
||||||
@php
|
@php
|
||||||
isset($member->pronoun) ? $pronoun = $member->pronoun : $pronoun = '';
|
isset($member->pronoun) ? $pronoun = $member->pronoun : $pronoun = '';
|
||||||
@endphp
|
@endphp
|
||||||
<label>Pronouns</label><br />
|
<label>Pronouns</label><br />
|
||||||
<input type="text" name="pronouns" value="{{$pronoun}}" />
|
<input type="text" name="pronouns" value="{{$pronoun}}" />
|
||||||
<br />
|
<br />
|
||||||
@php
|
@php
|
||||||
isset($member->role) ? $role = $member->role : $role = 2;
|
isset($member->role) ? $role = $member->role : $role = 2;
|
||||||
@endphp
|
//for creation of initial admin account
|
||||||
<label>Role</label><br />
|
if($mode == 'admin-create')
|
||||||
<input type="text" name="role" value="{{$role}}" />
|
{
|
||||||
<br />
|
$role = 0;
|
||||||
@if($mode == 'member-create')
|
}
|
||||||
<label>Fresh Password</label><br />
|
@endphp
|
||||||
<input type="password" id="fresh_pass" name="fresh_pass" value="" />
|
|
||||||
<br />
|
@if($mode != 'admin-create')
|
||||||
<label>Confirm Fresh Password</label><br />
|
<label>Role</label><br />
|
||||||
<input type="password" id="fresh_pass_confirm" name="fresh_pass_confirm" value="" />
|
<input type="text" name="role" value="{{$role}}" />
|
||||||
<br />
|
<br />
|
||||||
@endif
|
@endif
|
||||||
@php
|
|
||||||
|
@if($mode == 'member-create' || $mode == 'admin-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;
|
isset($member->active) ? $status = $member->active : $status = false;
|
||||||
@endphp
|
@endphp
|
||||||
<label>Status</label><br />
|
|
||||||
<select name="status">
|
@if($mode != 'admin-create')
|
||||||
@if($status)
|
<label>Status</label><br />
|
||||||
<option value="true" selected>Active</option>
|
<select name="status">
|
||||||
<option value="false">Not Active</option>
|
@if($status)
|
||||||
@else
|
<option value="true" selected>Active</option>
|
||||||
<option value="true">Active</option>
|
<option value="false">Not Active</option>
|
||||||
<option value="false" selected>Not Active</option>
|
@else
|
||||||
@endif
|
<option value="true">Active</option>
|
||||||
</select>
|
<option value="false" selected>Not Active</option>
|
||||||
<br />
|
@endif
|
||||||
</div>
|
</select>
|
||||||
@csrf
|
<br />
|
||||||
@php
|
@endif
|
||||||
|
|
||||||
|
</div>
|
||||||
|
@csrf
|
||||||
|
@php
|
||||||
isset($member->uuid) ? $uuid = $member->uuid : $uuid = 0;
|
isset($member->uuid) ? $uuid = $member->uuid : $uuid = 0;
|
||||||
@endphp
|
@endphp
|
||||||
<input type="hidden" name="id" value="{{$uuid}}" />
|
<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>
|
@ -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']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user