Merge branch 'ControlPanel-gg:development' into development

This commit is contained in:
Dennis 2023-03-09 12:32:58 +01:00 committed by GitHub
commit 4ae54d736f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 670 additions and 354 deletions

View file

@ -0,0 +1,67 @@
<?php
namespace App\Extensions\PaymentGateways\PayPal;
use Spatie\LaravelSettings\Settings;
class PayPalSettings extends Settings
{
public bool $enabled = false;
public ?string $client_id;
public ?string $client_secret;
public ?string $sandbox_client_id;
public ?string $sandbox_client_secret;
public static function group(): string
{
return 'paypal';
}
public static function encrypted(): array
{
return [
'client_id',
'client_secret',
'sandbox_client_id',
'sandbox_client_secret'
];
}
/**
* Summary of optionInputData array
* Only used for the settings page
* @return array<array<'type'|'label'|'description'|'options', string|bool|float|int|array<string, string>>>
*/
public static function getOptionInputData()
{
return [
'category_icon' => 'fas fa-dollar-sign',
'client_id' => [
'type' => 'string',
'label' => 'Client ID',
'description' => 'The Client ID of your PayPal App',
],
'client_secret' => [
'type' => 'string',
'label' => 'Client Secret',
'description' => 'The Client Secret of your PayPal App',
],
'enabled' => [
'type' => 'boolean',
'label' => 'Enabled',
'description' => 'Enable this payment gateway',
],
'sandbox_client_id' => [
'type' => 'string',
'label' => 'Sandbox Client ID',
'description' => 'The Sandbox Client ID used when app_env = local',
],
'sandbox_client_secret' => [
'type' => 'string',
'label' => 'Sandbox Client Secret',
'description' => 'The Sandbox Client Secret used when app_env = local',
],
];
}
}

View file

@ -6,8 +6,6 @@ function getConfig()
{
return [
"name" => "PayPal",
"description" => "PayPal payment gateway",
"RoutesIgnoreCsrf" => [],
"enabled" => (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID')) || (config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID') && env("APP_ENV") === "local"),
];
}

View file

@ -2,6 +2,7 @@
use App\Events\PaymentEvent;
use App\Events\UserUpdateCreditsEvent;
use App\Extensions\PaymentGateways\PayPal\PayPalSettings;
use App\Models\PartnerDiscount;
use App\Models\Payment;
use App\Models\ShopProduct;
@ -25,6 +26,8 @@ use PayPalHttp\HttpException;
*/
function PaypalPay(Request $request)
{
$settings = new PayPalSettings();
/** @var User $user */
$user = Auth::user();
$shopProduct = ShopProduct::findOrFail($request->shopProduct);
@ -111,6 +114,8 @@ function PaypalPay(Request $request)
*/
function PaypalSuccess(Request $laravelRequest)
{
$settings = new PayPalSettings();
$user = Auth::user();
$user = User::findOrFail($user->id);
@ -165,6 +170,8 @@ function PaypalSuccess(Request $laravelRequest)
*/
function getPayPalClient()
{
$settings = new PayPalSettings();
$environment = env('APP_ENV') == 'local'
? new SandboxEnvironment(getPaypalClientId(), getPaypalClientSecret())
: new ProductionEnvironment(getPaypalClientId(), getPaypalClientSecret());
@ -175,12 +182,14 @@ function getPayPalClient()
*/
function getPaypalClientId()
{
return env('APP_ENV') == 'local' ? config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID") : config("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID");
$settings = new PayPalSettings();
return env('APP_ENV') == 'local' ? $settings->sandbox_client_id : $settings->client_id;
}
/**
* @return string
*/
function getPaypalClientSecret()
{
return env('APP_ENV') == 'local' ? config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET") : config("SETTINGS::PAYMENTS:PAYPAL:SECRET");
$settings = new PayPalSettings();
return env('APP_ENV') == 'local' ? $settings->sandbox_client_secret : $settings->client_secret;
}

View file

@ -0,0 +1,100 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
use Illuminate\Support\Facades\DB;
class CreatePayPalSettings extends SettingsMigration
{
public function up(): void
{
$table_exists = DB::table('settings_old')->exists();
$this->migrator->addEncrypted('paypal.client_id', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') : null);
$this->migrator->addEncrypted('paypal.client_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:SECRET') : null);
$this->migrator->addEncrypted('paypal.sandbox_client_id', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID') : null);
$this->migrator->addEncrypted('paypal.sandbox_client_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET') : null);
$this->migrator->add('paypal.enabled', false);
}
public function down(): void
{
DB::table('settings_old')->insert([
[
'key' => 'SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID',
'value' => $this->getNewValue('client_id'),
'type' => 'string',
'description' => 'The Client ID of your PayPal App'
],
[
'key' => 'SETTINGS::PAYMENTS:PAYPAL:SECRET',
'value' => $this->getNewValue('client_secret'),
'type' => 'string',
'description' => 'The Client Secret of your PayPal App'
],
[
'key' => 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID',
'value' => $this->getNewValue('sandbox_client_id'),
'type' => 'string',
'description' => 'The Sandbox Client ID of your PayPal App'
],
[
'key' => 'SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET',
'value' => $this->getNewValue('sandbox_client_secret'),
'type' => 'string',
'description' => 'The Sandbox Client Secret of your PayPal App'
]
]);
$this->migrator->delete('paypal.client_id');
$this->migrator->delete('paypal.client_secret');
$this->migrator->delete('paypal.enabled');
$this->migrator->delete('paypal.sandbox_client_id');
$this->migrator->delete('paypal.sandbox_client_secret');
}
public function getNewValue(string $name)
{
$new_value = DB::table('settings')->where([['group', '=', 'paypal'], ['name', '=', $name]])->get(['payload'])->first();
// Some keys returns '""' as a value.
if ($new_value->payload === '""') {
return null;
}
// remove the quotes from the string
if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
return substr($new_value->payload, 1, -1);
}
return $new_value->payload;
}
public function getOldValue(string $key)
{
// Always get the first value of the key.
$old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
// Handle the old values to return without it being a string in all cases.
if ($old_value->type === "string" || $old_value->type === "text") {
if (is_null($old_value->value)) {
return '';
}
// Some values have the type string, but their values are boolean.
if ($old_value->value === "false" || $old_value->value === "true") {
return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
}
return $old_value->value;
}
if ($old_value->type === "boolean") {
return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
}
return filter_var($old_value->value, FILTER_VALIDATE_INT);
}
}

View file

@ -0,0 +1,63 @@
<?php
namespace App\Extensions\PaymentGateways\Stripe;
use Spatie\LaravelSettings\Settings;
class StripeSettings extends Settings
{
public bool $enabled = false;
public ?string $secret_key;
public ?string $endpoint_secret;
public ?string $test_secret_key;
public ?string $test_endpoint_secret;
public static function group(): string
{
return 'stripe';
}
public static function encrypted(): array
{
return [
"secret_key",
"endpoint_secret",
"test_secret_key",
"test_endpoint_secret"
];
}
public static function getOptionInputData()
{
return [
'category_icon' => 'fas fa-dollar-sign',
'secret_key' => [
'type' => 'string',
'label' => 'Secret Key',
'description' => 'The Secret Key of your Stripe App',
],
'endpoint_secret' => [
'type' => 'string',
'label' => 'Endpoint Secret',
'description' => 'The Endpoint Secret of your Stripe App',
],
'test_secret_key' => [
'type' => 'string',
'label' => 'Test Secret Key',
'description' => 'The Test Secret Key used when app_env = local',
],
'test_endpoint_secret' => [
'type' => 'string',
'label' => 'Test Endpoint Secret',
'description' => 'The Test Endpoint Secret used when app_env = local',
],
'enabled' => [
'type' => 'boolean',
'label' => 'Enabled',
'description' => 'Enable this payment gateway',
]
];
}
}

View file

@ -6,10 +6,8 @@ function getConfig()
{
return [
"name" => "Stripe",
"description" => "Stripe payment gateway",
"RoutesIgnoreCsrf" => [
"payment/StripeWebhooks",
],
"enabled" => config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') && env("APP_ENV") === "local",
];
}

View file

@ -2,6 +2,7 @@
use App\Events\PaymentEvent;
use App\Events\UserUpdateCreditsEvent;
use App\Extensions\PaymentGateways\Stripe\StripeSettings;
use App\Models\PartnerDiscount;
use App\Models\Payment;
use App\Models\ShopProduct;
@ -79,7 +80,6 @@ function StripePay(Request $request)
],
'mode' => 'payment',
'payment_method_types' => str_getcsv(config('SETTINGS::PAYMENTS:STRIPE:METHODS')),
'success_url' => route('payment.StripeSuccess', ['payment' => $payment->id]) . '&session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => route('payment.Cancel'),
'payment_intent_data' => [
@ -244,9 +244,11 @@ function getStripeClient()
*/
function getStripeSecret()
{
$settings = new StripeSettings();
return env('APP_ENV') == 'local'
? config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET')
: config('SETTINGS::PAYMENTS:STRIPE:SECRET');
? $settings->test_secret_key
: $settings->secret_key;
}
/**
@ -254,9 +256,10 @@ function getStripeSecret()
*/
function getStripeEndpointSecret()
{
$settings = new StripeSettings();
return env('APP_ENV') == 'local'
? config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET')
: config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET');
? $settings->test_endpoint_secret
: $settings->endpoint_secret;
}
/**
* @param $amount

View file

@ -0,0 +1,98 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
use Illuminate\Support\Facades\DB;
class CreateStripeSettings extends SettingsMigration
{
public function up(): void
{
$table_exists = DB::table('settings_old')->exists();
$this->migrator->addEncrypted('stripe.secret_key', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:SECRET') : null);
$this->migrator->addEncrypted('stripe.endpoint_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') : null);
$this->migrator->addEncrypted('stripe.test_secret_key', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') : null);
$this->migrator->addEncrypted('stripe.test_endpoint_secret', $table_exists ? $this->getOldValue('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET') : null);
$this->migrator->add('stripe.enabled', false);
}
public function down(): void
{
DB::table('settings_old')->insert([
[
'key' => 'SETTINGS::PAYMENTS:STRIPE:SECRET',
'value' => $this->getNewValue('secret_key'),
'type' => 'string',
'description' => 'The Secret Key of your Stripe App'
],
[
'key' => 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET',
'value' => $this->getNewValue('endpoint_secret'),
'type' => 'string',
'description' => 'The Endpoint Secret of your Stripe App'
],
[
'key' => 'SETTINGS::PAYMENTS:STRIPE:TEST_SECRET',
'value' => $this->getNewValue('test_secret_key'),
'type' => 'string',
'description' => 'The Test Secret Key of your Stripe App'
],
[
'key' => 'SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET',
'value' => $this->getNewValue('test_endpoint_secret'),
'type' => 'string',
'description' => 'The Test Endpoint Secret of your Stripe App'
]
]);
$this->migrator->delete('stripe.secret_key');
$this->migrator->delete('stripe.endpoint_secret');
$this->migrator->delete('stripe.enabled');
$this->migrator->delete('stripe.test_secret_key');
$this->migrator->delete('stripe.test_endpoint_secret');
}
public function getNewValue(string $name)
{
$new_value = DB::table('settings')->where([['group', '=', 'stripe'], ['name', '=', $name]])->get(['payload'])->first();
// Some keys returns '""' as a value.
if ($new_value->payload === '""') {
return null;
}
// remove the quotes from the string
if (substr($new_value->payload, 0, 1) === '"' && substr($new_value->payload, -1) === '"') {
return substr($new_value->payload, 1, -1);
}
return $new_value->payload;
}
public function getOldValue(string $key)
{
// Always get the first value of the key.
$old_value = DB::table('settings_old')->where('key', '=', $key)->get(['value', 'type'])->first();
// Handle the old values to return without it being a string in all cases.
if ($old_value->type === "string" || $old_value->type === "text") {
if (is_null($old_value->value)) {
return '';
}
// Some values have the type string, but their values are boolean.
if ($old_value->value === "false" || $old_value->value === "true") {
return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
}
return $old_value->value;
}
if ($old_value->type === "boolean") {
return filter_var($old_value->value, FILTER_VALIDATE_BOOL);
}
return filter_var($old_value->value, FILTER_VALIDATE_INT);
}
}

View file

@ -2,6 +2,9 @@
namespace App\Helpers;
/**
* Summary of ExtensionHelper
*/
class ExtensionHelper
{
/**
@ -60,7 +63,7 @@ class ExtensionHelper
/**
* Get all extensions
* @return array
* @return array of all extension paths look like: app/Extensions/ExtensionNamespace/ExtensionName
*/
public static function getAllExtensions()
{
@ -79,4 +82,75 @@ class ExtensionHelper
return $extensions;
}
/**
* Summary of getAllExtensionMigrations
* @return array of all migration paths look like: app/Extensions/ExtensionNamespace/ExtensionName/migrations/
*/
public static function getAllExtensionMigrations()
{
$extensions = ExtensionHelper::getAllExtensions();
// get all migration directories of the extensions and return them as array
$migrations = [];
foreach ($extensions as $extension) {
$migrationDir = $extension . '/migrations';
if (file_exists($migrationDir)) {
$migrations[] = $migrationDir;
}
}
return $migrations;
}
/**
* Summary of getAllExtensionSettings
* @return array of all setting classes look like: App\Extensions\PaymentGateways\PayPal\PayPalSettings
*/
public static function getAllExtensionSettingsClasses()
{
$extensions = ExtensionHelper::getAllExtensions();
$settings = [];
foreach ($extensions as $extension) {
$extensionName = basename($extension);
$settingFile = $extension . '/' . $extensionName . 'Settings.php';
if (file_exists($settingFile)) {
// remove the base path from the setting file path to get the namespace
$settingFile = str_replace(app_path() . '/', '', $settingFile);
$settingFile = str_replace('.php', '', $settingFile);
$settingFile = str_replace('/', '\\', $settingFile);
$settingFile = 'App\\' . $settingFile;
$settings[] = $settingFile;
}
}
return $settings;
}
public static function getExtensionSettings(string $extensionName)
{
$extensions = ExtensionHelper::getAllExtensions();
// find the setting file of the extension and return an instance of it
foreach ($extensions as $extension) {
if (!(basename($extension) == $extensionName)) {
continue;
}
$extensionName = basename($extension);
$settingFile = $extension . '/' . $extensionName . 'Settings.php';
if (file_exists($settingFile)) {
// remove the base path from the setting file path to get the namespace
$settingFile = str_replace(app_path() . '/', '', $settingFile);
$settingFile = str_replace('.php', '', $settingFile);
$settingFile = str_replace('/', '\\', $settingFile);
$settingFile = 'App\\' . $settingFile;
return new $settingFile();
}
}
}
}

View file

@ -51,7 +51,10 @@ class PaymentController extends Controller
// build a paymentgateways array that contains the routes for the payment gateways and the image path for the payment gateway which lays in public/images/Extensions/PaymentGateways with the extensionname in lowercase
foreach ($extensions as $extension) {
$extensionName = basename($extension);
if (!ExtensionHelper::getExtensionConfig($extensionName, 'enabled')) continue; // skip if not enabled
$extensionSettings = ExtensionHelper::getExtensionSettings($extensionName);
if ($extensionSettings->enabled == false) continue;
$payment = new \stdClass();
$payment->name = ExtensionHelper::getExtensionConfig($extensionName, 'name');

View file

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin;
use App\Helpers\ExtensionHelper;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
@ -25,13 +26,26 @@ class SettingsController extends Controller
// get all other settings in app/Settings directory
// group items by file name like $categories
$settings = collect();
foreach (scandir(app_path('Settings')) as $file) {
if (in_array($file, ['.', '..'])) {
continue;
}
$className = 'App\\Settings\\' . str_replace('.php', '', $file);
$settings_classes = [];
// get all app settings
$app_settings = scandir(app_path('Settings'));
$app_settings = array_diff($app_settings, ['.', '..']);
// append App\Settings to class name
foreach ($app_settings as $app_setting) {
$settings_classes[] = 'App\\Settings\\' . str_replace('.php', '', $app_setting);
}
// get all extension settings
$settings_files = array_merge($settings_classes, ExtensionHelper::getAllExtensionSettingsClasses());
foreach ($settings_files as $file) {
$className = $file;
// instantiate the class and call toArray method to get all options
$options = (new $className())->toArray();
// call getOptionInputData method to get all options
if (method_exists($className, 'getOptionInputData')) {
$optionInputData = $className::getOptionInputData();
} else {
@ -54,8 +68,9 @@ class SettingsController extends Controller
if (isset($optionInputData['category_icon'])) {
$optionsData['category_icon'] = $optionInputData['category_icon'];
}
$optionsData['settings_class'] = $className;
$settings[str_replace('Settings.php', '', $file)] = $optionsData;
$settings[str_replace('Settings', '', class_basename($className))] = $optionsData;
}
$settings->sort();
@ -77,10 +92,10 @@ class SettingsController extends Controller
public function update(Request $request)
{
$category = request()->get('category');
$settings_class = request()->get('settings_class');
$className = 'App\\Settings\\' . $category . 'Settings';
if (method_exists($className, 'getValidations')) {
$validations = $className::getValidations();
if (method_exists($settings_class, 'getValidations')) {
$validations = $settings_class::getValidations();
} else {
$validations = [];
}
@ -91,7 +106,7 @@ class SettingsController extends Controller
return Redirect::to('admin/settings' . '#' . $category)->withErrors($validator)->withInput();
}
$settingsClass = new $className();
$settingsClass = new $settings_class();
foreach ($settingsClass->toArray() as $key => $value) {
switch (gettype($value)) {

View file

@ -22,20 +22,13 @@ class ShopProductController extends Controller
*
* @return Application|Factory|View|Response
*/
public function index(LocaleSettings $locale_settings)
public function index(LocaleSettings $locale_settings, GeneralSettings $general_settings)
{
$isPaymentSetup = false;
$isStoreEnabled = $general_settings->store_enabled;
if (
env('APP_ENV') == 'local' ||
config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') ||
config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:METHODS')
) {
$isPaymentSetup = true;
}
return view('admin.store.index', [
'isPaymentSetup' => $isPaymentSetup,
'isStoreEnabled' => $isStoreEnabled,
'locale_datatables' => $locale_settings->datatables
]);
}

View file

@ -12,29 +12,21 @@ class StoreController extends Controller
/** Display a listing of the resource. */
public function index(UserSettings $user_settings, GeneralSettings $general_settings)
{
$isPaymentSetup = false;
if (
env('APP_ENV') == 'local' ||
config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID') ||
config('SETTINGS::PAYMENTS:STRIPE:SECRET') && config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') && config('SETTINGS::PAYMENTS:STRIPE:METHODS')
) {
$isPaymentSetup = true;
}
$isStoreEnabled = $general_settings->store_enabled;
//Required Verification for creating an server
if ($user_settings->force_email_verification && ! Auth::user()->hasVerifiedEmail()) {
if ($user_settings->force_email_verification && !Auth::user()->hasVerifiedEmail()) {
return redirect()->route('profile.index')->with('error', __('You are required to verify your email address before you can purchase credits.'));
}
//Required Verification for creating an server
if ($user_settings->force_discord_verification && ! Auth::user()->discordUser) {
if ($user_settings->force_discord_verification && !Auth::user()->discordUser) {
return redirect()->route('profile.index')->with('error', __('You are required to link your discord account before you can purchase Credits'));
}
return view('store.index')->with([
'products' => ShopProduct::where('disabled', '=', false)->orderBy('type', 'asc')->orderBy('price', 'asc')->get(),
'isPaymentSetup' => true,
'isStoreEnabled' => $isStoreEnabled,
'credits_display_name' => $general_settings->credits_display_name
]);
}

View file

@ -2,6 +2,7 @@
namespace App\Providers;
use App\Extensions\PaymentGateways\PayPal\PayPalSettings;
use App\Models\UsefulLink;
use App\Settings\MailSettings;
use Exception;
@ -10,7 +11,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Qirolab\Theme\Theme;
class AppServiceProvider extends ServiceProvider
{
@ -64,91 +65,5 @@ class AppServiceProvider extends ServiceProvider
$settings = $this->app->make(MailSettings::class);
$settings->setConfig();
//only run if the installer has been executed
// try {
// $settings = Settings::all();
// // Set all configs from database
// foreach ($settings as $setting) {
// config([$setting->key => $setting->value]);
// }
// if(!file_exists(base_path('themes') . "/" . config("SETTINGS::SYSTEM:THEME"))){
// config(['SETTINGS::SYSTEM:THEME' => "default"]);
// }
// if(config('SETTINGS::SYSTEM:THEME') !== config('theme.active')){
// Theme::set(config("SETTINGS::SYSTEM:THEME"), "default");
// }
// // Set Mail Config
// //only update config if mail settings have changed in DB
// if (
// config('mail.default') != config('SETTINGS:MAIL:MAILER') ||
// config('mail.mailers.smtp.host') != config('SETTINGS:MAIL:HOST') ||
// config('mail.mailers.smtp.port') != config('SETTINGS:MAIL:PORT') ||
// config('mail.mailers.smtp.username') != config('SETTINGS:MAIL:USERNAME') ||
// config('mail.mailers.smtp.password') != config('SETTINGS:MAIL:PASSWORD') ||
// config('mail.mailers.smtp.encryption') != config('SETTINGS:MAIL:ENCRYPTION') ||
// config('mail.from.address') != config('SETTINGS:MAIL:FROM_ADDRESS') ||
// config('mail.from.name') != config('SETTINGS:MAIL:FROM_NAME')
// ) {
// config(['mail.default' => config('SETTINGS::MAIL:MAILER')]);
// config(['mail.mailers.smtp' => [
// 'transport' => 'smtp',
// 'host' => config('SETTINGS::MAIL:HOST'),
// 'port' => config('SETTINGS::MAIL:PORT'),
// 'encryption' => config('SETTINGS::MAIL:ENCRYPTION'),
// 'username' => config('SETTINGS::MAIL:USERNAME'),
// 'password' => config('SETTINGS::MAIL:PASSWORD'),
// 'timeout' => null,
// 'auth_mode' => null,
// ]]);
// config(['mail.from' => ['address' => config('SETTINGS::MAIL:FROM_ADDRESS'), 'name' => config('SETTINGS::MAIL:FROM_NAME')]]);
// Artisan::call('queue:restart');
// }
// // Set Recaptcha API Config
// // Load recaptcha package if recaptcha is enabled
// if (config('SETTINGS::RECAPTCHA:ENABLED') == 'true') {
// $this->app->register(\Biscolab\ReCaptcha\ReCaptchaServiceProvider::class);
// }
// //only update config if recaptcha settings have changed in DB
// if (
// config('recaptcha.api_site_key') != config('SETTINGS::RECAPTCHA:SITE_KEY') ||
// config('recaptcha.api_secret_key') != config('SETTINGS::RECAPTCHA:SECRET_KEY')
// ) {
// config(['recaptcha.api_site_key' => config('SETTINGS::RECAPTCHA:SITE_KEY')]);
// config(['recaptcha.api_secret_key' => config('SETTINGS::RECAPTCHA:SECRET_KEY')]);
// Artisan::call('config:clear');
// Artisan::call('cache:clear');
// }
// try {
// $stringfromfile = file(base_path().'/.git/HEAD');
// $firstLine = $stringfromfile[0]; //get the string from the array
// $explodedstring = explode('/', $firstLine, 3); //seperate out by the "/" in the string
// $branchname = $explodedstring[2]; //get the one that is always the branch name
// } catch (Exception $e) {
// $branchname = 'unknown';
// Log::notice($e);
// }
// config(['BRANCHNAME' => $branchname]);
// // Set Discord-API Config
// config(['services.discord.client_id' => config('SETTINGS::DISCORD:CLIENT_ID')]);
// config(['services.discord.client_secret' => config('SETTINGS::DISCORD:CLIENT_SECRET')]);
// } catch (Exception $e) {
// error_log('Settings Error: Could not load settings from database. The Installation probably is not done yet.');
// error_log($e);
// Log::error('Settings Error: Could not load settings from database. The Installation probably is not done yet.');
// Log::error($e);
// }
}
}

View file

@ -6,6 +6,7 @@ use Spatie\LaravelSettings\Settings;
class GeneralSettings extends Settings
{
public bool $store_enabled = true;
public string $credits_display_name;
public bool $recaptcha_enabled;
public string $recaptcha_site_key;
@ -31,27 +32,6 @@ class GeneralSettings extends Settings
];
}
/**
* Summary of validations array
* @return array<string, string>
*/
public static function getValidations()
{
return [
'credits_display_name' => 'required|string',
'initial_user_credits' => 'required|numeric',
'initial_server_limit' => 'required|numeric',
'recaptcha_enabled' => 'nullable|string',
'recaptcha_site_key' => 'nullable|string',
'recaptcha_secret_key' => 'nullable|string',
'phpmyadmin_url' => 'nullable|string',
'alert_enabled' => 'nullable|string',
'alert_type' => 'nullable|string',
'alert_message' => 'nullable|string',
'theme' => 'required|string'
];
}
/**
* Summary of optionTypes
* Only used for the settings page
@ -61,6 +41,11 @@ class GeneralSettings extends Settings
{
return [
'category_icon' => "fas fa-cog",
'store_enabled' => [
'type' => 'boolean',
'label' => 'Enable Store',
'description' => 'Enable the store for users to purchase credits.'
],
'credits_display_name' => [
'type' => 'string',
'label' => 'Credits Display Name',

View file

@ -1,5 +1,6 @@
<?php
use App\Helpers\ExtensionHelper;
use App\Settings\GeneralSettings;
use App\Settings\DiscordSettings;
use App\Settings\InvoiceSettings;
@ -29,7 +30,7 @@ return [
ServerSettings::class,
UserSettings::class,
WebsiteSettings::class,
TicketSettings::class
TicketSettings::class,
],
/*
@ -44,6 +45,8 @@ return [
*/
'migrations_paths' => [
database_path('settings'),
...ExtensionHelper::getAllExtensionMigrations()
],
/*
@ -88,7 +91,7 @@ return [
'global_casts' => [
DateTimeInterface::class => Spatie\LaravelSettings\SettingsCasts\DateTimeInterfaceCast::class,
DateTimeZone::class => Spatie\LaravelSettings\SettingsCasts\DateTimeZoneCast::class,
// Spatie\DataTransferObject\DataTransferObject::class => Spatie\LaravelSettings\SettingsCasts\DtoCast::class,
// Spatie\DataTransferObject\DataTransferObject::class => Spatie\LaravelSettings\SettingsCasts\DtoCast::class,
Spatie\LaravelData\Data::class => Spatie\LaravelSettings\SettingsCasts\DataCast::class,
],

View file

@ -1,34 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('settings_old');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::create('settings_old', function (Blueprint $table) {
$table->string('key', 191)->primary();
$table->text('value')->nullable();
$table->string('type');
$table->longText('description')->nullable();
$table->timestamps();
});
}
};
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('settings_old');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::create('settings_old', function (Blueprint $table) {
$table->string('key', 191)->primary();
$table->text('value')->nullable();
$table->string('type');
$table->longText('description')->nullable();
$table->timestamps();
});
}
};

View file

@ -10,6 +10,7 @@ class CreateGeneralSettings extends SettingsMigration
$table_exists = DB::table('settings_old')->exists();
// Get the user-set configuration values from the old table.
$this->migrator->add('general.store_enabled', true);
$this->migrator->add('general.credits_display_name', $table_exists ? $this->getOldValue('SETTINGS::SYSTEM:CREDITS_DISPLAY_NAME') : 'Credits');
$this->migrator->addEncrypted('general.recaptcha_site_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SITE_KEY") : env('RECAPTCHA_SITE_KEY', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'));
$this->migrator->addEncrypted('general.recaptcha_secret_key', $table_exists ? $this->getOldValue("SETTINGS::RECAPTCHA:SECRET_KEY") : env('RECAPTCHA_SECRET_KEY', '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe'));
@ -88,6 +89,7 @@ class CreateGeneralSettings extends SettingsMigration
],
]);
$this->migrator->delete('general.store_enabled');
$this->migrator->delete('general.credits_display_name');
$this->migrator->delete('general.recaptcha_site_key');
$this->migrator->delete('general.recaptcha_secret_key');

View file

@ -71,10 +71,12 @@
<form action="{{ route('admin.settings.update') }}" method="POST">
@csrf
@method('POST')
<input type="hidden" name="settings_class"
value="{{ $options['settings_class'] }}">
<input type="hidden" name="category" value="{{ $category }}">
@foreach ($options as $key => $value)
@if ($key == 'category_icon')
@if ($key == 'category_icon' || $key == 'settings_class')
@continue
@endif
<div class="row">

View file

@ -168,139 +168,132 @@
<!-- /.card-body -->
</div>
@endif
<!-- /.card -->
</div>
<!-- /.col -->
<div class="col-md-6">
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">
<i class="fas fa-history mr-2"></i>
{{ __('Activity Logs') }}
</h3>
</div>
<!-- /.card-header -->
<div class="card-body py-0 pb-2">
<ul class="list-group list-group-flush">
@foreach (Auth::user()->actions()->take(8)->orderBy('created_at', 'desc')->get() as $log)
<li class="list-group-item d-flex justify-content-between text-muted">
<span>
@if (str_starts_with($log->description, 'created'))
<small><i class="fas text-success fa-plus mr-2"></i></small>
@elseif(str_starts_with($log->description, 'redeemed'))
<small><i class="fas text-success fa-money-check-alt mr-2"></i></small>
@elseif(str_starts_with($log->description, 'deleted'))
<small><i class="fas text-danger fa-times mr-2"></i></small>
@elseif(str_starts_with($log->description, 'gained'))
<small><i class="fas text-success fa-money-bill mr-2"></i></small>
@elseif(str_starts_with($log->description, 'updated'))
<small><i class="fas text-info fa-pen mr-2"></i></small>
@endif
{{ explode('\\', $log->subject_type)[2] }}
{{ ucfirst($log->description) }}
</span>
<small>
{{ $log->created_at->diffForHumans() }}
</small>
</li>
@endforeach
</ul>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
@if ($referral_settings->enabled)
<!--PartnerDiscount::getDiscount()--->
<div class="col-md-6">
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">
<i class="fas fa-handshake mr-2"></i>
{{ __('Partner program') }}
<i class="fas fa-history mr-2"></i>
{{ __('Activity Logs') }}
</h3>
</div>
<!-- /.card-header -->
<div class="card-body py-0 pb-2">
@if (
($referral_settings->allowed == 'client' && Auth::user()->role != 'member') ||
$referral_settings->allowed == 'everyone')
<div class="row">
<div class="mt-3 col-md-8">
<span class="badge badge-success" style="font-size: 14px">
<i class="fa fa-user-check mr-2"></i>
{{ __('Your referral URL') }}:
<span onmouseover="hoverIn()" onmouseout="hoverOut()" onclick="onClickCopy()"
id="RefLink" style="cursor: pointer;">
{{ __('Click to copy') }}
</span>
<ul class="list-group list-group-flush">
@foreach (Auth::user()->actions()->take(8)->orderBy('created_at', 'desc')->get() as $log)
<li class="list-group-item d-flex justify-content-between text-muted">
<span>
@if (str_starts_with($log->description, 'created'))
<small><i class="fas text-success fa-plus mr-2"></i></small>
@elseif(str_starts_with($log->description, 'redeemed'))
<small><i class="fas text-success fa-money-check-alt mr-2"></i></small>
@elseif(str_starts_with($log->description, 'deleted'))
<small><i class="fas text-danger fa-times mr-2"></i></small>
@elseif(str_starts_with($log->description, 'gained'))
<small><i class="fas text-success fa-money-bill mr-2"></i></small>
@elseif(str_starts_with($log->description, 'updated'))
<small><i class="fas text-info fa-pen mr-2"></i></small>
@endif
{{ explode('\\', $log->subject_type)[2] }}
{{ ucfirst($log->description) }}
</span>
</div>
<div class="mt-3 col-md-4">
<span class="badge badge-info"
style="font-size: 14px">{{ __('Number of referred users:') }}
{{ $numberOfReferrals }}</span>
</div>
</div>
@if ($partnerDiscount)
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-bottom: 0px">
<table class="table">
<thead>
<tr>
<th>{{ __('Your discount') }}</th>
<th>{{ __('Discount for your new users') }}</th>
<th>{{ __('Reward per registered user') }}</th>
<th>{{ __('New user payment commision') }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $partnerDiscount->partner_discount }}%</td>
<td>{{ $partnerDiscount->registered_user_discount }}%</td>
<td>{{ $referral_settings->reward }}
{{ $general_settings->credits_display_name }}</td>
<td>{{ $partnerDiscount->referral_system_commission == -1 ? $referral_settings->percentage : $partnerDiscount->referral_system_commission }}%
</td>
</tr>
</tbody>
</table>
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-top: 0px">
@else
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-bottom: 0px">
<table class="table">
<thead>
<tr>
<th>{{ __('Reward per registered user') }}</th>
<th>{{ __('New user payment commision') }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $referral_settings->reward }}
{{ $general_settings->credits_display_name }}</td>
<td>{{ $referral_settings->percentage }}%</td>
</tr>
</tbody>
</table>
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-top: 0px">
@endif
@else
<span class="badge badge-warning"><i class="fa fa-user-check mr-2"></i>
{{ __('Make a purchase to reveal your referral-URL') }}</span>
@endif
<small>
{{ $log->created_at->diffForHumans() }}
</small>
</li>
@endforeach
</ul>
</div>
<!-- /.card-body -->
</div>
@endif
<!-- /.card -->
</div>
<!-- /.col -->
</div>
<!-- END CUSTOM CONTENT -->
<!-- /.card -->
@if ($referral_settings->enabled)
<!--PartnerDiscount::getDiscount()--->
<div class="card card-default">
<div class="card-header">
<h3 class="card-title">
<i class="fas fa-handshake mr-2"></i>
{{ __('Partner program') }}
</h3>
</div>
<!-- /.card-header -->
<div class="card-body py-0 pb-2">
@if (
($referral_settings->allowed == 'client' && Auth::user()->role != 'member') ||
$referral_settings->allowed == 'everyone')
<div class="row">
<div class="mt-3 col-md-8">
<span class="badge badge-success" style="font-size: 14px">
<i class="fa fa-user-check mr-2"></i>
{{ __('Your referral URL') }}:
<span onmouseover="hoverIn()" onmouseout="hoverOut()" onclick="onClickCopy()"
id="RefLink" style="cursor: pointer;">
{{ __('Click to copy') }}
</span>
</span>
</div>
<div class="mt-3 col-md-4">
<span class="badge badge-info"
style="font-size: 14px">{{ __('Number of referred users:') }}
{{ $numberOfReferrals }}</span>
</div>
</div>
@if ($partnerDiscount)
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-bottom: 0px">
<table class="table">
<thead>
<tr>
<th>{{ __('Your discount') }}</th>
<th>{{ __('Discount for your new users') }}</th>
<th>{{ __('Reward per registered user') }}</th>
<th>{{ __('New user payment commision') }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $partnerDiscount->partner_discount }}%</td>
<td>{{ $partnerDiscount->registered_user_discount }}%</td>
<td>{{ $referral_settings->reward }}
{{ $general_settings->credits_display_name }}</td>
<td>{{ $partnerDiscount->referral_system_commission == -1 ? $referral_settings->percentage : $partnerDiscount->referral_system_commission }}%
</td>
</tr>
</tbody>
</table>
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-top: 0px">
@else
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-bottom: 0px">
<table class="table">
<thead>
<tr>
<th>{{ __('Reward per registered user') }}</th>
<th>{{ __('New user payment commision') }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $referral_settings->reward }}
{{ $general_settings->credits_display_name }}</td>
<td>{{ $referral_settings->percentage }}%</td>
</tr>
</tbody>
</table>
<hr
style="width: 100%; height:1px; border-width:0; background-color:#6c757d; margin-top: 0px">
@endif
@else
<span class="badge badge-warning"><i class="fa fa-user-check mr-2"></i>
{{ __('Make a purchase to reveal your referral-URL') }}</span>
@endif
</div>
<!-- /.card-body -->
</div>
@endif
<!-- /.card -->
</div>
</div>
</section>
<!-- END CONTENT -->

View file

@ -3,13 +3,16 @@
<head>
@php($website_settings = app(App\Settings\WebsiteSettings::class))
@php($general_settings = app(App\Settings\GeneralSettings::class))
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta content="{{ $website_settings->seo_title }}" property="og:title">
<meta content="{{ $website_settings->seo_description }}" property="og:description">
<meta content='{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('logo.png') ? asset('storage/logo.png') : asset('images/controlpanel_logo.png') }}' property="og:image">
<meta
content='{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('logo.png') ? asset('storage/logo.png') : asset('images/controlpanel_logo.png') }}'
property="og:image">
<title>{{ config('app.name', 'Laravel') }}</title>
<link rel="icon"
href="{{ \Illuminate\Support\Facades\Storage::disk('public')->exists('favicon.ico') ? asset('storage/favicon.ico') : asset('favicon.ico') }}"
@ -87,11 +90,11 @@
</li>
<!-- End Language Selection -->
@endif
@foreach($useful_links as $link)
<li class="nav-item d-none d-sm-inline-block">
<a href="{{ $link->link }}" class="nav-link" target="__blank"><i
class="{{$link->icon}}"></i> {{ $link->title }}</a>
</li>
@foreach ($useful_links as $link)
<li class="nav-item d-none d-sm-inline-block">
<a href="{{ $link->link }}" class="nav-link" target="__blank"><i
class="{{ $link->icon }}"></i> {{ $link->title }}</a>
</li>
@endforeach
</ul>
@ -232,11 +235,7 @@
</a>
</li>
@if (env('APP_ENV') == 'local' ||
(config('SETTINGS::PAYMENTS:PAYPAL:SECRET') && config('SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID')) ||
(config('SETTINGS::PAYMENTS:STRIPE:SECRET') &&
config('SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET') &&
config('SETTINGS::PAYMENTS:STRIPE:METHODS')))
@if (env('APP_ENV') == 'local' || $general_settings->store_enabled)
<li class="nav-item">
<a href="{{ route('store.index') }}"
class="nav-link @if (Request::routeIs('store.*') || Request::routeIs('checkout')) active @endif">
@ -384,7 +383,7 @@
<li class="nav-item">
<a href="{{ route('admin.legal.index') }}"
class="nav-link @if (Request::routeIs('admin.legal.*')) active @endif">
class="nav-link @if (Request::routeIs('admin.legal.*')) active @endif">
<i class="nav-icon fas fa-link"></i>
<p>{{ __('Legal Sites') }}</p>
</a>
@ -458,7 +457,8 @@
<a target="_blank" href="{{ route('privacy') }}"><strong>{{ __('Privacy') }}</strong></a>
@endif
@if ($website_settings->show_tos)
| <a target="_blank" href="{{ route('tos') }}"><strong>{{ __('Terms of Service') }}</strong></a>
| <a target="_blank"
href="{{ route('tos') }}"><strong>{{ __('Terms of Service') }}</strong></a>
@endif
</div>
</footer>

View file

@ -10,10 +10,9 @@
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a class=""
href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a class="" href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item"><a class="text-muted"
href="{{ route('store.index') }}">{{ __('Store') }}</a></li>
href="{{ route('store.index') }}">{{ __('Store') }}</a></li>
</ol>
</div>
</div>
@ -31,8 +30,7 @@
</button>
</div>
@if ($isPaymentSetup && $products->count() > 0)
@if ($isStoreEnabled && $products->count() > 0)
<div class="card">
<div class="card-header">
<h5 class="card-title"><i class="fa fa-coins mr-2"></i>{{ $credits_display_name }}</h5>
@ -40,43 +38,48 @@
<div class="card-body">
<table class="table table-striped table-responsive-sm">
<thead>
<tr>
<th>{{ __('Price') }}</th>
<th>{{ __('Type') }}</th>
<th>{{ __('Description') }}</th>
<th></th>
</tr>
<tr>
<th>{{ __('Price') }}</th>
<th>{{ __('Type') }}</th>
<th>{{ __('Description') }}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($products as $product)
<tr>
<td>{{ $product->formatToCurrency($product->price) }}</td>
<td>{{ strtolower($product->type) == 'credits' ? $credits_display_name : $product->type }}</td>
<td>
@if(strtolower($product->type) == 'credits')
<i class="fa fa-coins mr-2"></i>
@elseif (strtolower($product->type) == 'server slots')
<i class="fa fa-server mr-2"></i>
@endif
@foreach ($products as $product)
<tr>
<td>{{ $product->formatToCurrency($product->price) }}</td>
<td>{{ strtolower($product->type) == 'credits' ? $credits_display_name : $product->type }}
</td>
<td>
@if (strtolower($product->type) == 'credits')
<i class="fa fa-coins mr-2"></i>
@elseif (strtolower($product->type) == 'server slots')
<i class="fa fa-server mr-2"></i>
@endif
{{ $product->display }}</td>
<td><a href="{{ route('checkout', $product->id) }}"
class="btn btn-info">{{ __('Purchase') }}</a>
</td>
</tr>
@endforeach
{{ $product->display }}
</td>
<td><a href="{{ route('checkout', $product->id) }}"
class="btn btn-info">{{ __('Purchase') }}</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@else
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> @if ($products->count() == 0) {{ __('There are no store products!') }} @else {{ __('The store is not correctly configured!') }} @endif
<h4><i class="icon fa fa-ban"></i>
@if ($products->count() == 0)
{{ __('There are no store products!') }}
@else
{{ __('The store is not correctly configured!') }}
@endif
</h4>
</div>
@endif