Initialer Laravel Commit für BetiX
This commit is contained in:
56
app/Http/Controllers/Admin/GeoBlockController.php
Normal file
56
app/Http/Controllers/Admin/GeoBlockController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AppSetting;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class GeoBlockController extends Controller
|
||||
{
|
||||
private const KEY = 'geo.settings';
|
||||
|
||||
private array $defaults = [
|
||||
'enabled' => false,
|
||||
'blocked_countries' => [],
|
||||
'allowed_countries' => [],
|
||||
'mode' => 'blacklist', // 'blacklist' or 'whitelist'
|
||||
'vpn_block' => false,
|
||||
'vpn_provider' => 'none', // 'none', 'ipqualityscore', 'proxycheck'
|
||||
'vpn_api_key' => '',
|
||||
'block_message' => 'This service is not available in your region.',
|
||||
'redirect_url' => '',
|
||||
];
|
||||
|
||||
public function show()
|
||||
{
|
||||
$saved = AppSetting::get(self::KEY, []);
|
||||
$settings = array_merge($this->defaults, is_array($saved) ? $saved : []);
|
||||
|
||||
return Inertia::render('Admin/GeoBlock', [
|
||||
'settings' => $settings,
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'enabled' => 'boolean',
|
||||
'mode' => 'required|in:blacklist,whitelist',
|
||||
'blocked_countries' => 'array',
|
||||
'blocked_countries.*' => 'string|size:2',
|
||||
'allowed_countries' => 'array',
|
||||
'allowed_countries.*' => 'string|size:2',
|
||||
'vpn_block' => 'boolean',
|
||||
'vpn_provider' => 'required|in:none,ipqualityscore,proxycheck',
|
||||
'vpn_api_key' => 'nullable|string|max:200',
|
||||
'block_message' => 'required|string|max:500',
|
||||
'redirect_url' => 'nullable|url|max:500',
|
||||
]);
|
||||
|
||||
AppSetting::put(self::KEY, $data);
|
||||
|
||||
return back()->with('success', 'GeoBlock settings saved.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user