feat: ✨ Added Server owner transfer
This commit is contained in:
parent
1a75d63ba1
commit
7d81fa6247
|
@ -7,6 +7,7 @@ use App\Models\Nest;
|
||||||
use App\Models\Node;
|
use App\Models\Node;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Client\PendingRequest;
|
use Illuminate\Http\Client\PendingRequest;
|
||||||
use Illuminate\Http\Client\Response;
|
use Illuminate\Http\Client\Response;
|
||||||
|
@ -373,6 +374,21 @@ class Pterodactyl
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the owner of a server
|
||||||
|
*
|
||||||
|
* @param int $userId
|
||||||
|
* @param Server $server
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function updateServerOwner(Server $server, int $userId)
|
||||||
|
{
|
||||||
|
return self::client()->patch("/application/servers/{$server->pterodactyl_id}/details", [
|
||||||
|
'name' => $server->name,
|
||||||
|
'user' => $userId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Power Action Specific Server
|
* Power Action Specific Server
|
||||||
*
|
*
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
||||||
use App\Classes\Pterodactyl;
|
use App\Classes\Pterodactyl;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Models\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
@ -66,8 +67,12 @@ class ServerController extends Controller
|
||||||
*/
|
*/
|
||||||
public function edit(Server $server)
|
public function edit(Server $server)
|
||||||
{
|
{
|
||||||
|
// get all users from the database
|
||||||
|
$users = User::all();
|
||||||
|
|
||||||
return view('admin.servers.edit')->with([
|
return view('admin.servers.edit')->with([
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
|
'users' => $users,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,15 +81,36 @@ class ServerController extends Controller
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @return Response
|
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, Server $server)
|
public function update(Request $request, Server $server)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'identifier' => 'required|string',
|
'identifier' => 'required|string',
|
||||||
|
'user_id' => 'required|integer',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$server->update($request->all());
|
|
||||||
|
if ($request->get('user_id') != $server->user_id) {
|
||||||
|
// find the user
|
||||||
|
$user = User::findOrFail($request->get('user_id'));
|
||||||
|
|
||||||
|
// try to update the owner on pterodactyl
|
||||||
|
try {
|
||||||
|
$response = Pterodactyl::updateServerOwner($server, $user->pterodactyl_id);
|
||||||
|
if ($response->getStatusCode() != 200) {
|
||||||
|
return redirect()->back()->with('error', 'Failed to update server owner on pterodactyl');
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the owner on the database
|
||||||
|
$server->user_id = $user->id;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return redirect()->back()->with('error', 'Internal Server Error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the identifier
|
||||||
|
$server->identifier = $request->get('identifier');
|
||||||
|
$server->save();
|
||||||
|
|
||||||
return redirect()->route('admin.servers.index')->with('success', 'Server updated!');
|
return redirect()->route('admin.servers.index')->with('success', 'Server updated!');
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<ol class="breadcrumb float-sm-right">
|
<ol class="breadcrumb float-sm-right">
|
||||||
<li class="breadcrumb-item"><a href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{route('admin.servers.index')}}">{{__('Servers')}}</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('admin.servers.index') }}">{{ __('Servers') }}</a>
|
||||||
|
</li>
|
||||||
<li class="breadcrumb-item"><a class="text-muted"
|
<li class="breadcrumb-item"><a class="text-muted"
|
||||||
href="{{ route('admin.servers.edit', $server->id) }}">{{ __('Edit') }}</a></li>
|
href="{{ route('admin.servers.edit', $server->id) }}">{{ __('Edit') }}</a></li>
|
||||||
</ol>
|
</ol>
|
||||||
|
@ -40,14 +41,32 @@
|
||||||
@csrf
|
@csrf
|
||||||
@method('PATCH')
|
@method('PATCH')
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">{{__('Server identifier')}}</label>
|
<label for="identifier">{{ __('Server identifier') }}</label>
|
||||||
<input value="{{$server->identifier}}" id="identifier" name="identifier" type="text"
|
<input value="{{ $server->identifier }}" id="identifier" name="identifier"
|
||||||
class="form-control @error('identifier') is-invalid @enderror" required="required">
|
type="text" class="form-control @error('identifier') is-invalid @enderror"
|
||||||
|
required="required">
|
||||||
@error('identifier')
|
@error('identifier')
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
{{ $message }}
|
{{ $message }}
|
||||||
</div>
|
</div>
|
||||||
@enderror
|
@enderror
|
||||||
|
|
||||||
|
|
||||||
|
<label for="user_id">{{ __('Server owner') }}</label>
|
||||||
|
<select name="user_id" id="user_id" class="form-control">
|
||||||
|
@foreach ($users as $user)
|
||||||
|
<option value="{{ $user->id }}"
|
||||||
|
@if ($user->id == $server->user_id) selected @endif>{{ $user->name }}
|
||||||
|
({{ $user->email }})
|
||||||
|
({{ $user->id }})
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@error('user_id')
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
{{ $message }}
|
||||||
|
</div>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group text-right">
|
<div class="form-group text-right">
|
||||||
|
@ -63,5 +82,4 @@
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
<!-- END CONTENT -->
|
<!-- END CONTENT -->
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in a new issue