[FEATURE] Server owner transfer
[FEATURE] Server owner transfer
This commit is contained in:
commit
e978cb9914
|
@ -7,6 +7,7 @@ use App\Models\Nest;
|
|||
use App\Models\Node;
|
||||
use App\Models\Product;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
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
|
||||
*
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
|||
use App\Classes\Pterodactyl;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Server;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
@ -66,8 +67,12 @@ class ServerController extends Controller
|
|||
*/
|
||||
public function edit(Server $server)
|
||||
{
|
||||
// get all users from the database
|
||||
$users = User::all();
|
||||
|
||||
return view('admin.servers.edit')->with([
|
||||
'server' => $server,
|
||||
'users' => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -76,15 +81,36 @@ class ServerController extends Controller
|
|||
*
|
||||
* @param Request $request
|
||||
* @param Server $server
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request, Server $server)
|
||||
{
|
||||
$request->validate([
|
||||
'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!');
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<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"
|
||||
href="{{ route('admin.servers.edit', $server->id) }}">{{ __('Edit') }}</a></li>
|
||||
</ol>
|
||||
|
@ -40,9 +41,14 @@
|
|||
@csrf
|
||||
@method('PATCH')
|
||||
<div class="form-group">
|
||||
<label for="name">{{__('Server identifier')}}</label>
|
||||
<input value="{{$server->identifier}}" id="identifier" name="identifier" type="text"
|
||||
class="form-control @error('identifier') is-invalid @enderror" required="required">
|
||||
<label for="identifier">{{ __('Server identifier') }}
|
||||
<i data-toggle="popover" data-trigger="hover"
|
||||
data-content="{{ __('Change the server identifier on controlpanel to match a pterodactyl server.') }}"
|
||||
class="fas fa-info-circle"></i>
|
||||
</label>
|
||||
<input value="{{ $server->identifier }}" id="identifier" name="identifier"
|
||||
type="text" class="form-control @error('identifier') is-invalid @enderror"
|
||||
required="required">
|
||||
@error('identifier')
|
||||
<div class="invalid-feedback">
|
||||
{{ $message }}
|
||||
|
@ -50,9 +56,30 @@
|
|||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group text-right">
|
||||
<button type="submit" class="btn btn-primary">{{__('Submit')}}</button>
|
||||
<div class="form-group">
|
||||
<label for="user_id">{{ __('Server owner') }}
|
||||
<i data-toggle="popover" data-trigger="hover"
|
||||
data-content="{{ __('Change the current server owner on controlpanel and pterodactyl.') }}"
|
||||
class="fas fa-info-circle"></i>
|
||||
</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>
|
||||
|
||||
<button type="submit" class="btn btn-primary">{{ __('Submit') }}</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -63,5 +90,4 @@
|
|||
|
||||
</section>
|
||||
<!-- END CONTENT -->
|
||||
|
||||
@endsection
|
||||
|
|
Loading…
Reference in a new issue