1
0
mirror of https://koodu.h-i.works/projects/thebadspace synced 2025-06-25 16:04:37 -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 515de4c56b
commit 56f445572f
6 changed files with 194 additions and 111 deletions

View File

@ -6,39 +6,49 @@ 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()
{
//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');
//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) {
$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)

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

@ -60,25 +60,43 @@ class MemberRepository
public function add($request)
{
$password = [];
$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"];
}
$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 role paramter is set, not an admin add
if (isset($request->role)) {
$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(),
]);
} 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!"];