浏览代码

fix: 🚑️ Added more improved validation & Fixed Language Settings

IceToast 3 年之前
父节点
当前提交
7ca6438f35

+ 19 - 0
app/Classes/Settings/Language.php

@@ -6,6 +6,8 @@ use App\Models\Settings;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Session;
+use Illuminate\Support\Facades\Validator;
+
 
 class Language
 {
@@ -17,6 +19,19 @@ class Language
 
     public function updateSettings(Request $request)
     {
+        $validator = Validator::make($request->all(), [
+            'autotranslate' => 'string',
+            'canClientChangeLanguage' => 'boolean',
+            'defaultLanguage' => 'required|string',
+            'languages' => 'required|array',
+            'languages.*' => 'required|string',
+            'datatable-language' => 'required|string',
+        ]);
+
+
+        if ($validator->fails()) {
+            return redirect(route('admin.settings.index') . '#language')->with('error', __('Language settings have not been updated!'))->withErrors($validator);
+        }
 
         $values = [
             //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
@@ -31,6 +46,10 @@ class Language
         foreach ($values as $key => $value) {
             $param = $request->get($value);
 
+            if (is_array($param)) {
+                $param = implode(",", $param);
+            }
+
             Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]);
             Cache::forget("setting" . ':' . $key);
             Session::remove("locale");

+ 16 - 4
app/Classes/Settings/Misc.php

@@ -6,7 +6,7 @@ use App\Models\Settings;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Config;
-use Illuminate\Support\Facades\Session;
+use Illuminate\Support\Facades\Validator;
 
 class Misc
 {
@@ -19,21 +19,33 @@ class Misc
 
     public function updateSettings(Request $request)
     {
-        $request->validate([
+        $validator = Validator::make($request->all(), [
             'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
             'favicon' => 'nullable|max:10000|mimes:ico',
+            'discord-bot-token' => 'nullable|string',
+            'discord-client-id' => 'nullable|string',
+            'discord-client-secret' => 'nullable|string',
+            'discord-guild-id' => 'nullable|string',
+            'discord-invite-url' => 'nullable|string',
+            'discord-role-id' => 'nullable|string',
+            'recaptcha-site-key' => 'nullable|string',
+            'recaptcha-secret-key' => 'nullable|string',
+            'enable-recaptcha' => 'nullable|boolean',
         ]);
 
+        if ($validator->fails()) {
+            return redirect(route('admin.settings.index') . '#misc')->with('error', __('Misc settings have not been updated!'))->withErrors($validator)
+                ->withInput();
+        }
+
         if ($request->hasFile('icon')) {
             $request->file('icon')->storeAs('public', 'icon.png');
         }
-
         if ($request->hasFile('favicon')) {
             $request->file('favicon')->storeAs('public', 'favicon.ico');
         }
 
         $values = [
-            //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
             "SETTINGS::DISCORD:BOT_TOKEN" => "discord-bot-token",
             "SETTINGS::DISCORD:CLIENT_ID" => "discord-client-id",
             "SETTINGS::DISCORD:CLIENT_SECRET" => "discord-client-secret",

+ 18 - 1
app/Classes/Settings/Payments.php

@@ -5,7 +5,8 @@ namespace App\Classes\Settings;
 use App\Models\Settings;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
-use Illuminate\Support\Facades\Session;
+use Illuminate\Support\Facades\Validator;
+
 
 class Payments
 {
@@ -17,6 +18,22 @@ class Payments
 
     public function updateSettings(Request $request)
     {
+        $validator = Validator::make($request->all(), [
+            "paypal-client_id" => "nullable|string",
+            "paypal-client-secret" => "nullable|string",
+            "paypal-sandbox-secret" => "nullable|string",
+            "stripe-secret-key" => "nullable|string",
+            "stripe-endpoint-secret" => "nullable|string",
+            "stripe-test-secret-key" => "nullable|string",
+            "stripe-test-endpoint-secret" => "nullable|string",
+            "stripe-methods" => "nullable|string",
+            "sales-tax" => "nullable|numeric",
+        ]);
+
+        if ($validator->fails()) {
+            return redirect(route('admin.settings.index') . '#payment')->with('error', __('Payment settings have not been updated!'))->withErrors($validator)
+                ->withInput();
+        }
 
         $values = [
             //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)

+ 1 - 1
app/Classes/Settings/System.php

@@ -37,7 +37,7 @@ class System
         ]);
 
         if ($validator->fails()) {
-            return redirect(route('admin.settings.index') . '#system')->with('error', __('System settings not updated!'))->withErrors($validator)
+            return redirect(route('admin.settings.index') . '#system')->with('error', __('System settings have not been updated!'))->withErrors($validator)
                 ->withInput();
         }
 

+ 5 - 6
app/Http/Middleware/SetLocale.php

@@ -22,17 +22,16 @@ class SetLocale
     public function handle($request, Closure $next)
     {
         if (Session::has('locale')) {
-            $locale = Session::get('locale', Settings::getValueByKey("SETTINGS::LOCALE:DEFAULT"));
+            $locale = Session::get('locale', config("SETTINGS::LOCALE:DEFAULT"));
         } else {
-            if (Settings::getValueByKey("SETTINGS::LOCALE:DYNAMIC")!=="true") {
-                $locale = Settings::getValueByKey("SETTINGS::LOCALE:DEFAULT");
+            if (config("SETTINGS::LOCALE:DYNAMIC") !== "true") {
+                $locale = config("SETTINGS::LOCALE:DEFAULT");
             } else {
                 $locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
 
-                if (!in_array($locale, json_decode(Settings::getValueByKey("SETTINGS::LOCALE:AVAILABLE")))) {
-                    $locale = Settings::getValueByKey("SETTINGS::LOCALE:DEFAULT");
+                if (!in_array($locale, explode(',', config("SETTINGS::LOCALE:AVAILABLE")))) {
+                    $locale = config("SETTINGS::LOCALE:DEFAULT");
                 }
-
             }
         }
         App::setLocale($locale);

+ 11 - 4
resources/lang/de.json

@@ -68,7 +68,7 @@
     "User ID": "User-ID",
     "Server Creation Error": "Fehler beim erstellen des Servers",
     "Your servers have been suspended!": "Deine Server wurden pausiert",
-    "To automatically re-enable your server\/s, you need to purchase more credits.": "Um deine Server zu reaktivieren, musst du mehr Credits kaufen!",
+    "To automatically re-enable your server/s, you need to purchase more credits.": "Um deine Server zu reaktivieren, musst du mehr Credits kaufen!",
     "Purchase credits": "Credits kaufen",
     "If you have any questions please let us know.": "Solltest du weiter fragen haben, melde dich gerne beim Support!",
     "Regards": "mit freundlichen Grüßen",
@@ -217,7 +217,7 @@
     "A voucher can only be used one time per user. Uses specifies the number of different users that can use this voucher.": "Ein Gutschein kann von einem User nur einmal eingelöst werden. \"Benutzungen\" setzt die Anzahl an Usern die diesen Gutschein einlösen können.",
     "Max": "Max",
     "Expires at": "Läuft ab am",
-    "Used \/ Uses": "Benutzungen",
+    "Used / Uses": "Benutzungen",
     "Expires": "Ablauf",
     "Sign in to start your session": "Melde dich an um das Dashboard zu benutzen",
     "Password": "Passwort",
@@ -287,7 +287,7 @@
     "No nodes have been linked!": "Es wurde keine Nodes verknüpft",
     "No nests available!": "Keine Nests verfügbar",
     "No eggs have been linked!": "Es wurde keine Eggs verknüpft",
-    "Software \/ Games": "Software \/ Spiele",
+    "Software / Games": "Software / Spiele",
     "Please select software ...": "Bitte Software auswählen",
     "---": "---",
     "Specification ": "Spezifikation",
@@ -352,5 +352,12 @@
     "Please pay until": "Zahlbar bis",
     "Account already exists on Pterodactyl. Please contact the Support!": "Der Account existiert bereits bei Pterodactyl. Kontaktiere den Support!",
     "de": "Deutsch",
-    "en": "Englisch"
+    "en": "Englisch",
+    "fr": "Französisch",
+    "cs": "Tschechisch",
+    "es": "Spanisch",
+    "hi": "Hindi",
+    "it": "Italienisch",
+    "pl": "Polnisch",
+    "zh": "Chinesisch"
 }

+ 10 - 8
resources/views/admin/settings/tabs/language.blade.php

@@ -11,9 +11,12 @@
                     <div class="custom-control mb-3 p-0">
                         <label for="languages">{{ __('Available languages') }}:</label>
                         <select id="languages" style="width:100%" class="custom-select" name="languages[]" required
-                            multiple="multiple" autocomplete="off">
+                            multiple="multiple" autocomplete="off" @error('defaultLanguage') is-invalid @enderror>
+
                             @foreach (config('app.available_locales') as $lang)
-                                <option value="{{ $lang }}">{{ __($lang) }}</option>
+                                <option value="{{ $lang }}" @if (str_contains(config('SETTINGS::LOCALE:AVAILABLE'), $lang))  selected @endif>
+                                    {{ __($lang) }}
+                                </option>
                             @endforeach
                         </select>
                     </div>
@@ -28,11 +31,10 @@
                         </label>
 
                         <select id="defaultLanguage" style="width:100%" class="custom-select" name="defaultLanguage"
-                            required autocomplete="off">
-                            <option value="{{ config('SETTINGS::LOCALE:DEFAULT') }}" selected>
-                                {{ __(config('SETTINGS::LOCALE:DEFAULT')) }}</option>
+                            required autocomplete="off" @error('defaultLanguage') is-invalid @enderror>
                             @foreach (config('app.available_locales') as $lang)
-                                <option value="{{ $lang }}">{{ __($lang) }}</option>
+                                <option value="{{ $lang }}" @if (config('SETTINGS::LOCALE:DEFAULT') == $lang) selected
+                            @endif>{{ __($lang) }}</option>
                             @endforeach
                         </select>
                     </div>
@@ -40,8 +42,8 @@
                     <div class="custom-control mb-3 p-0">
                         <!--DATATABLE LANGUAGE -->
                         <label for="datatable-language">{{ __('Datable language') }} <i data-toggle="popover"
-                                data-trigger="hover"
-                                data-content="{{ __('The Language of the Datatables. Grab the Language-Codes from here') }} https://datatables.net/plug-ins/i18n/"
+                                data-trigger="hover" data-html="true"
+                                data-content="{{ __('The datatables lang-code. <br><strong>Example:</strong> en-gb, fr_fr, de_de<br>More Information: ') }} https://datatables.net/plug-ins/i18n/"
                                 class="fas fa-info-circle"></i></label>
                         <input x-model="datatable-language" id="datatable-language" name="datatable-language"
                             type="text" required value="{{ config('SETTINGS::LOCALE:DATATABLES') }}"

+ 3 - 3
resources/views/admin/settings/tabs/payment.blade.php

@@ -125,14 +125,14 @@
                 <div class="form-group mb-3">
                     <div class="custom-control p-0">
                         <div class="col m-0 p-0 d-flex justify-content-between align-items-center">
-                            <label for="sales_tax">{{ __('Tax Value in %') }}:</label>
+                            <label for="sales-tax">{{ __('Tax Value in %') }}:</label>
                             <i data-toggle="popover" data-trigger="hover" data-html="true"
                                 data-content="Tax Value that will be added to the total price of the order. <br><br> Example: 19 results in (19%)"
                                 class="fas fa-info-circle"></i>
                         </div>
-                        <input x-model="sales_tax" id="sales_tax" name="sales_tax" type="number"
+                        <input x-model="sales-tax" id="sales-tax" name="sales-tax" type="number"
                             value="{{ config('SETTINGS::PAYMENTS:SALES_TAX') }}"
-                            class="form-control @error('sales_tax') is-invalid @enderror">
+                            class="form-control @error('sales-tax') is-invalid @enderror">
                     </div>
                 </div>
             </div>