Use IDs instead of Role Names, Fix installer, Fix Register

This commit is contained in:
Dennis 2023-04-30 12:21:43 +02:00 committed by GitHub
commit 633a3d4dfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 75 deletions

View file

@ -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;
@ -105,26 +106,26 @@ class RoleController extends Controller
}
}
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'));
}
//}
}
/**
@ -135,14 +136,15 @@ class RoleController extends Controller
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();

View file

@ -139,6 +139,8 @@ class RegisterController extends Controller
]);
$user->syncRoles(4);
$response = $this->pterodactyl->application->post('/application/users', [
'external_id' => $user->pterodactyl_id,
'username' => $user->name,

View file

@ -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);
}

View file

@ -26,7 +26,7 @@ return new class extends Migration
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('pterodactyl_id')->nullable->change();
$table->integer('pterodactyl_id')->nullable()->change();
});
}
};

View file

@ -1,51 +0,0 @@
<?php
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Artisan::call('db:seed', [
'--class' => 'PermissionsSeeder',
]);
Schema::table('users', function ($table) {
$table->dropColumn('role');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function($table) {
$table->string('role')->default('member');
});
$users = User::with('roles')->get();
foreach($users as $user){
if($user->hasRole(1)){
$user->role = "admin";
}elseif ($user->hasRole(3)){
$user->role = "client";
}else{
$user->role = "member";
}
$user->save();
}
}
};

View file

@ -32,9 +32,14 @@ class PermissionsSeeder extends Seeder
$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);
}

View file

@ -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;
@ -77,6 +79,7 @@ if (isset($_POST['feedDB'])) {
$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');
@ -292,8 +295,9 @@ if (isset($_POST['createUser'])) {
}
$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');

View file

@ -255,7 +255,7 @@
</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">
@ -274,7 +274,7 @@
</li>
@endif
@if (Auth::user()->hasRole("Admin"))
@if (Auth::user()->hasRole(1))
<li class="nav-header">{{ __('Administration') }}</li>
<li class="nav-item">