Skip to content

Commit

Permalink
Use IDs instead of Role Names, Fix installer, Fix Register
Browse files Browse the repository at this point in the history
  • Loading branch information
1day2die authored Apr 30, 2023
2 parents 3ff60bf + e8c8d1c commit 633a3d4
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 75 deletions.
30 changes: 16 additions & 14 deletions app/Http/Controllers/Admin/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;
use Exception;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
Expand Down Expand Up @@ -105,26 +106,26 @@ public function update(Request $request, Role $role)
}
}

if($role->id == 3 || $role->id == 1 || $role->id == 4){ //dont let the user change the names of these roles
$role->update([
'color' => $request->color
]);
}else{
//if($role->id == 1 || $role->id == 3 || $role->id == 4){ //dont let the user change the names of these roles
// $role->update([
// 'color' => $request->color
// ]);
//}else{
$role->update([
'name' => $request->name,
'color' => $request->color
]);
}
//}

if($role->id == 1){
return redirect()->route('admin.roles.index')->with('success', __('Role updated. Name and Permissions of this Role cannot be changed'));
}elseif($role->id == 4 || $role->id == 3){
return redirect()->route('admin.roles.index')->with('success', __('Role updated. Name of this Role cannot be changed'));
}else{
//if($role->id == 1){
// return redirect()->route('admin.roles.index')->with('success', __('Role updated. Name and Permissions of this Role cannot be changed'));
//}elseif($role->id == 4 || $role->id == 3){
// return redirect()->route('admin.roles.index')->with('success', __('Role updated. Name of this Role cannot be changed'));
// }else{
return redirect()
->route('admin.roles.index')
->with('success', __('Role saved'));
}
//}
}

/**
Expand All @@ -135,14 +136,15 @@ public function update(Request $request, Role $role)
public function destroy(Role $role)
{

if($role->id == 3 || $role->id == 1 || $role->id == 2){ //cannot delete the hard coded roles
if($role->id == 1 || $role->id == 3 || $role->id == 4){ //cannot delete the hard coded roles
return back()->with("error","You cannot delete that role");
}

$users = User::role($role)->get();

foreach($users as $user){
$user->syncRoles(['Member']);
//$user->syncRoles(['Member']);
$user->syncRoles(4);
}

$role->delete();
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ protected function create(array $data)

]);

$user->syncRoles(4);

$response = $this->pterodactyl->application->post('/application/users', [
'external_id' => $user->pterodactyl_id,
'username' => $user->name,
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/isAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class isAdmin
*/
public function handle(Request $request, Closure $next)
{
if (Auth::user() && Auth::user()->hasRole("Admin")) {
//if (Auth::user() && Auth::user()->hasRole("Admin")) {
if (Auth::user() && Auth::user()->hasRole(1)) {
return $next($request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function up()
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('pterodactyl_id')->nullable->change();
$table->integer('pterodactyl_id')->nullable()->change();
});
}
};
51 changes: 0 additions & 51 deletions database/migrations/2023_04_29_233120_drop_roles.php

This file was deleted.

11 changes: 8 additions & 3 deletions database/seeders/PermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ public function run()
$admin->syncRoles(1);
}

$admins = User::where("role","client")->get();
foreach($admins as $admin) {
$admin->syncRoles(3);
$mods = User::where("role","moderator")->get();
foreach($mods as $mod) {
$mod->syncRoles(2);
}

$clients = User::where("role","client")->get();
foreach($clients as $client) {
$client->syncRoles(3);
}


Expand Down
10 changes: 7 additions & 3 deletions public/install/forms.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
Expand Down Expand Up @@ -77,6 +79,7 @@
$logs .= run_console('php artisan storage:link');
$logs .= run_console('php artisan migrate --seed --force');
$logs .= run_console('php artisan db:seed --class=ExampleItemsSeeder --force');
$logs .= run_console('php artisan db:seed --class=PermissionsSeeder --force');

wh_log($logs, 'debug');

Expand Down Expand Up @@ -292,8 +295,9 @@
}

$random = generateRandomString();
$query1 = 'INSERT INTO `' . getenv('DB_DATABASE') . "`.`users` (`name`, `credits`, `server_limit`, `pterodactyl_id`, `email`, `password`, `created_at`, `referral_code`) VALUES ('$name', 'admin', '250', '1', '$pteroID', '$mail', '$pass', CURRENT_TIMESTAMP, '$random')";
$query2 = 'INSERT INTO `' . getenv('DB_DATABASE') . "`.`model_has_roles` (`role_id`, `model_type`, `model_id`) VALUES ('1', 'App\Models\User', '1')";

$query1 = 'INSERT INTO `' . getenv('DB_DATABASE') . "`.`users` (`name`, `role`, `credits`, `server_limit`, `pterodactyl_id`, `email`, `password`, `created_at`, `referral_code`) VALUES ('$name', 'admin', '250', '1', '$pteroID', '$mail', '$pass', CURRENT_TIMESTAMP, '$random')";
$query2 = "INSERT INTO `" . getenv('DB_DATABASE') . "`.`model_has_roles` (`role_id`, `model_type`, `model_id`) VALUES ('1', 'App\\\Models\\\User', '1')";
if ($db->query($query1) && $db->query($query2)) {
wh_log('Created user with Email ' . $mail . ' and pterodactyl ID ' . $pteroID, 'info');
header('LOCATION: index.php?step=7');
Expand Down
4 changes: 2 additions & 2 deletions themes/default/views/layouts/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class="nav-link @if (Request::routeIs('ticket.*')) active @endif">
</li>
@endif

@if ((Auth::user()->hasRole("Admin") || Auth::user()->role == 'moderator') && $ticket_enabled)
@if ((Auth::user()->hasRole(1) || Auth::user()->role == 'moderator') && $ticket_enabled)
<li class="nav-header">{{ __('Moderation') }}</li>

<li class="nav-item">
Expand All @@ -274,7 +274,7 @@ class="nav-link @if (Request::routeIs('moderator.ticket.blacklist')) active @end
</li>
@endif

@if (Auth::user()->hasRole("Admin"))
@if (Auth::user()->hasRole(1))
<li class="nav-header">{{ __('Administration') }}</li>

<li class="nav-item">
Expand Down

0 comments on commit 633a3d4

Please sign in to comment.