From 7ca6438f35fa29b173c869dccd02ebe647e66dd9 Mon Sep 17 00:00:00 2001 From: IceToast Date: Sat, 15 Jan 2022 01:25:27 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Added=20more=20i?= =?UTF-8?q?mproved=20validation=20&=20Fixed=20Language=20Settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Classes/Settings/Language.php | 19 ++++++++++++++++++ app/Classes/Settings/Misc.php | 20 +++++++++++++++---- app/Classes/Settings/Payments.php | 19 +++++++++++++++++- app/Classes/Settings/System.php | 2 +- app/Http/Middleware/SetLocale.php | 11 +++++----- resources/lang/de.json | 15 ++++++++++---- .../admin/settings/tabs/language.blade.php | 18 +++++++++-------- .../admin/settings/tabs/payment.blade.php | 6 +++--- 8 files changed, 83 insertions(+), 27 deletions(-) diff --git a/app/Classes/Settings/Language.php b/app/Classes/Settings/Language.php index 1d59614a..eb956595 100644 --- a/app/Classes/Settings/Language.php +++ b/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"); diff --git a/app/Classes/Settings/Misc.php b/app/Classes/Settings/Misc.php index 073b6123..776028d9 100644 --- a/app/Classes/Settings/Misc.php +++ b/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", diff --git a/app/Classes/Settings/Payments.php b/app/Classes/Settings/Payments.php index 2accf807..197515e6 100644 --- a/app/Classes/Settings/Payments.php +++ b/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) diff --git a/app/Classes/Settings/System.php b/app/Classes/Settings/System.php index 5b0264e6..a159132a 100644 --- a/app/Classes/Settings/System.php +++ b/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(); } diff --git a/app/Http/Middleware/SetLocale.php b/app/Http/Middleware/SetLocale.php index 2abbccbe..bd5188b0 100644 --- a/app/Http/Middleware/SetLocale.php +++ b/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); diff --git a/resources/lang/de.json b/resources/lang/de.json index 02244845..284f23ac 100644 --- a/resources/lang/de.json +++ b/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" } diff --git a/resources/views/admin/settings/tabs/language.blade.php b/resources/views/admin/settings/tabs/language.blade.php index c4bd2e65..97617199 100644 --- a/resources/views/admin/settings/tabs/language.blade.php +++ b/resources/views/admin/settings/tabs/language.blade.php @@ -11,9 +11,12 @@
@@ -28,11 +31,10 @@ @@ -40,8 +42,8 @@
- +
- + class="form-control @error('sales-tax') is-invalid @enderror">