Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

super admin page #194

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cncnet-api/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,35 @@ public function editPlayerName(Request $request)
$request->session()->flash('success', "Player name has been updated to " . $player->username);
return redirect()->to($url);
}

/**
* God view only. Returns users who are in group 'Moderator' or 'Admin' or 'God'
*/
public function getSuperAdmin(Request $request)
{
if ($request->user() == null || !$request->user()->isGod())
return response('Unauthorized.', 401);

$users = \App\User::where('group', 'Moderator')
->orWhere('group', 'Admin')
->orWhere('group', 'God')
->get();
$groups = User::getPossibleEnumValues('group');

return view(
"admin.super_admin",
[
"users" => $users,
"groups" => $groups
]
);
}


}



function ini_to_b($string)
{
if ($string == "Null") return null;
Expand Down
8 changes: 8 additions & 0 deletions cncnet-api/app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public function handle($request, Closure $next)
}
}

if (isset($actions["isGod"]))
{
if (!$this->auth->user()->isGod()) //user must be 'god' to view this page
{
return response('Unauthorized.', 401);
}
}

if (!$this->auth->user()->isGod())
{
$response = null;
Expand Down
2 changes: 2 additions & 0 deletions cncnet-api/app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

Route::get('/admin', ['middleware' => 'auth', 'canEditAnyLadders' => true, 'uses' => 'AdminController@getAdminIndex']);

Route::get('/admin/super', ['middleware' => 'auth', 'isGod' => true, 'uses' => 'AdminController@getSuperAdmin']);

Route::group(['prefix' => 'admin/', 'middleware' => 'auth', 'canEditAnyLadders' => true], function ()
{
Route::get('players/ratings', 'AdminController@getPlayerRatings');
Expand Down
13 changes: 13 additions & 0 deletions cncnet-api/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Mail;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Support\Facades\Log;
use DB;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, JWTSubject
{
Expand Down Expand Up @@ -323,4 +324,16 @@ public function getCachedUserTierByLadderHistoryAndPlayer($history, $player)
{
return $player->getCachedPlayerTierByLadderHistory($history);
}

public static function getPossibleEnumValues($name){
$instance = new static; // create an instance of the model to be able to get the table name
$type = DB::select( DB::raw('SHOW COLUMNS FROM ' . $instance->getTable() . ' WHERE Field = "' . $name . '"') )[0]->Type;
preg_match('/^enum\((.*)\)$/', $type, $matches);
$enum = array();
foreach(explode(',', $matches[1]) as $value){
$v = trim( $value, "'" );
$enum[] = $v;
}
return $enum;
}
}
45 changes: 45 additions & 0 deletions cncnet-api/resources/views/admin/super_admin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@extends('layouts.app')
@section('title', 'Super Admin')

@section('feature-image', '/images/feature/feature-index.jpg')

@section('feature')
<div class="feature pt-5 pb-5">
<div class="container px-4 py-5 text-light">
<div class="row flex-lg-row-reverse align-items-center g-5 py-5">
<div class="col-12">
<h1 class="display-4 lh-1 mb-3 text-uppercase">
<strong class="fw-bold">CnCNet</strong>
<span>Super Admin</span>
</h1>
</div>
</div>

</div>
</div>
@endsection

@section('content')
<section class="mt-4">
<div class="container">

<table class="table col-md-12">
<thead>
<tr>
<th>Username</th>
<th>Group</th>
</tr>
</thead>
<tbody class="table">
@foreach ($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->group }}</td>
</tr>
@endforeach
</tbody>
</table>

</div>
</section>
@endsection