feat: Added validation on enable upgrade system & disabled upgrade route if not enabled

This commit is contained in:
IceToast 2022-08-16 22:33:59 +02:00
parent 5bf5abfda7
commit ff5ad1e2bd
4 changed files with 17 additions and 2 deletions

View file

@ -46,6 +46,14 @@ public function checkPteroClientkey(){
"enable-upgrades" => "string",
]);
$validator->after(function ($validator) use ($request) {
// if enable-recaptcha is true then recaptcha-site-key and recaptcha-secret-key must be set
if ($request->get('enable-upgrades') == 'true' && (!$request->get('pterodactyl-admin-api-key'))) {
$validator->errors()->add('pterodactyl-admin-api-key', 'The admin api key is required when upgrades are enabled.');
}
});
if ($validator->fails()) {
return redirect(route('admin.settings.index') . '#system')->with('error', __('System settings have not been updated!'))->withErrors($validator)
->withInput();

View file

@ -257,7 +257,7 @@ class ServerController extends Controller
public function upgrade(Server $server, Request $request)
{
if($server->user_id != Auth::user()->id || !config("SETTINGS::SYSTEM:ENABLE_UPGRADE")) return redirect()->route('servers.index');
if($server->user_id != Auth::user()->id) return redirect()->route('servers.index');
if(!isset($request->product_upgrade))
{
return redirect()->route('servers.show', ['server' => $server->id])->with('error', __('this product is the only one'));

View file

@ -91,6 +91,11 @@
<input x-model="pterodactyl-admin-api-key" id="pterodactyl-admin-api-key" name="pterodactyl-admin-api-key"
type="text" value="{{ config('SETTINGS::SYSTEM:PTERODACTYL:ADMIN_USER_TOKEN') }}"
class="form-control @error('pterodactyl-admin-api-key') is-invalid @enderror" required>
@error('pterodactyl-admin-api-key')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div>
<a href="{{route('admin.settings.checkPteroClientkey')}}"> <button type="button" class="btn btn-secondary">{{__("Test API")}}</button></a>
</div>

View file

@ -64,7 +64,9 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
Route::get('notifications/readAll',[NotificationController::class,'readAll'])->name('notifications.readAll');
Route::resource('notifications', NotificationController::class);
Route::resource('servers', ServerController::class);
if(config('SETTINGS::SYSTEM:ENABLE_UPGRADE')){
Route::post('servers/{server}/upgrade', [ServerController::class,'upgrade'])->name('servers.upgrade');
}
Route::resource('profile', ProfileController::class);
Route::resource('store', StoreController::class);