Skip to content

Commit

Permalink
v1.0.4 (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
1day2die authored Jan 15, 2025
2 parents 7767d88 + d3deaab commit 3e12163
Show file tree
Hide file tree
Showing 57 changed files with 1,507 additions and 1,287 deletions.
30 changes: 23 additions & 7 deletions app/Extensions/PaymentGateways/Stripe/StripeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class StripeExtension extends AbstractExtension
{
use CouponTrait;

// https://docs.stripe.com/currencies#zero-decimal
protected const ZERO_DECIMAL_CURRENCIES = [
'BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF',
];

// https://docs.stripe.com/currencies#three-decimal
protected const THREE_DECIMAL_CURRENCIES = [
'BHD', 'JOD', 'KWD', 'OMR', 'TND',
];

public static function getConfig(): array
{
return [
Expand Down Expand Up @@ -51,7 +61,7 @@ public static function getRedirectUrl(Payment $payment, ShopProduct $shopProduct
'name' => $shopProduct->display,
'description' => $shopProduct->description,
],
'unit_amount_decimal' => self::priceInCents($totalPriceString),
'unit_amount_decimal' => self::convertAmount($totalPriceString, $shopProduct->currency_code),
],
'quantity' => 1,
],
Expand Down Expand Up @@ -363,11 +373,17 @@ public static function checkPriceAmount(float $amount, string $currencyCode, st
];
return $amount >= $minimums[$currencyCode][$payment_method];
}
public static function priceInCents($price){
$centPrice = str_replace(".", "", $price);
$centPrice = str_replace(",", "", $centPrice);
//$centPrice = str_pad($centPrice, 4, '0', STR_PAD_RIGHT);
return $centPrice;
}

protected static function convertAmount(float $amount, string $currency): int
{
if (in_array($currency, self::ZERO_DECIMAL_CURRENCIES, true)) {
return $amount;
}

if (in_array($currency, self::THREE_DECIMAL_CURRENCIES, true)) {
return $amount * 1000;
}

return $amount * 100;
}
}
48 changes: 0 additions & 48 deletions app/Http/Controllers/Admin/LegalController.php

This file was deleted.

44 changes: 33 additions & 11 deletions app/Http/Controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Storage;
use Qirolab\Theme\Theme;

class SettingsController extends Controller
{
const ICON_PERMISSION = "admin.icons.edit";



/**
* Display a listing of the resource.
*
* @return Application|Factory|View|Response
*/
public function index()
{


// get all other settings in app/Settings directory
// group items by file name like $categories
$settings = collect();
Expand Down Expand Up @@ -78,20 +75,41 @@ public function index()
if (isset($optionInputData['category_icon'])) {
$optionsData['category_icon'] = $optionInputData['category_icon'];
}

if (isset($optionInputData['position'])) {
$optionsData['position'] = $optionInputData['position'];
}else{
$optionsData['position'] = 99;
}

$optionsData['settings_class'] = $className;

$settings[str_replace('Settings', '', class_basename($className))] = $optionsData;
}

$settings->sort();

$settings = $settings->sortBy('position');

$themes = array_diff(scandir(base_path('themes')), array('..', '.'));

$images = [
'icon' => Storage::disk('local')->exists('public/icon.png')
? asset('storage/icon.png') . '?v=' . filemtime(Storage::path('public/icon.png'))
: asset('images/ctrlpanel_logo.png'),

'logo' => Storage::disk('local')->exists('public/logo.png')
? asset('storage/logo.png') . '?v=' . filemtime(Storage::path('public/logo.png'))
: asset('images/ctrlpanel_logo.png'),

'favicon' => Storage::disk('local')->exists('public/favicon.ico')
? asset('storage/favicon.ico') . '?v=' . filemtime(Storage::path('public/favicon.ico'))
: asset('images/ctrlpanel_logo.png'),
];

return view('admin.settings.index', [
'settings' => $settings->all(),
'themes' => $themes,
'active_theme' => Theme::active(),
'images' => $images
]);
}

Expand Down Expand Up @@ -149,12 +167,16 @@ public function updateIcons(Request $request)
{
$this->checkPermission(self::ICON_PERMISSION);

$request->validate([
'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
'favicon' => 'nullable|max:10000|mimes:ico',
$validator = Validator::make($request->all(), [
'icon' => 'nullable|max:10000|file|mimes:jpg,png,jpeg',
'logo' => 'nullable|max:10000|file|mimes:jpg,png,jpeg',
'favicon' => 'nullable|max:10000|file|mimes:ico,x-icon',
]);

if ($validator->fails()) {
return Redirect::to('admin/settings#icons')->withErrors($validator)->withInput();
}

if ($request->hasFile('icon')) {
$request->file('icon')->storeAs('public', 'icon.png');
}
Expand All @@ -165,6 +187,6 @@ public function updateIcons(Request $request)
$request->file('favicon')->storeAs('public', 'favicon.ico');
}

return Redirect::to('admin/settings')->with('success', 'Icons updated successfully.');
return Redirect::to('admin/settings#icons')->with('success', 'Icons updated successfully.');
}
}
13 changes: 11 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ public function username()

public function login(Request $request, GeneralSettings $general_settings)
{


$validationRules = [
$this->username() => 'required|string',
'password' => 'required|string',
];
if ($general_settings->recaptcha_enabled) {
$validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
if ($general_settings->recaptcha_version) {
switch ($general_settings->recaptcha_version) {
case "v2":
$validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
break;
case "v3":
$validationRules['g-recaptcha-response'] = ['required', 'recaptchav3:recaptchathree,0.5'];
break;
}
}
$request->validate($validationRules);

Expand Down
14 changes: 11 additions & 3 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RegisterController extends Controller
private $referral_mode;

private $referral_reward;
private $recaptcha_version;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -74,7 +75,7 @@ public function __construct(PterodactylSettings $ptero_settings, GeneralSettings
$this->middleware('guest');
$this->pterodactyl = new PterodactylClient($ptero_settings);
$this->credits_display_name = $general_settings->credits_display_name;
$this->recaptcha_enabled = $general_settings->recaptcha_enabled;
$this->recaptcha_version = $general_settings->recaptcha_version;
$this->website_show_tos = $website_settings->show_tos;
$this->register_ip_check = $user_settings->register_ip_check;
$this->initial_credits = $user_settings->initial_credits;
Expand All @@ -96,8 +97,15 @@ protected function validator(array $data)
'email' => ['required', 'string', 'email', 'max:64', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
];
if ($this->recaptcha_enabled) {
$validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
if ($this->recaptcha_version) {
switch ($this->recaptcha_version) {
case "v2":
$validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
break;
case "v3":
$validationRules['g-recaptcha-response'] = ['required', 'recaptchav3:recaptchathree,0.5'];
break;
}
}
if ($this->website_show_tos) {
$validationRules['terms'] = ['required'];
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ public function show(Server $server): \Illuminate\View\View

$serverAttributes = $this->pterodactyl->getServerAttributes($server->pterodactyl_id);
$upgradeOptions = $this->getUpgradeOptions($server, $serverAttributes);

return view('servers.settings')->with([
'server' => $server,
'serverAttributes' => $serverAttributes,
'products' => $upgradeOptions,
'server_enable_upgrade' => $this->serverSettings->enable_upgrade,
'credits_display_name' => $this->generalSettings->credits_display_name,
Expand All @@ -396,10 +396,15 @@ private function getUpgradeOptions(Server $server, array $serverInfo): \Illumina
$nodeId = $serverInfo['relationships']['node']['attributes']['id'];
$pteroNode = $this->pterodactyl->getNode($nodeId);

$currentProductEggs = $currentProduct->eggs->pluck('id')->toArray();

return Product::orderBy('created_at')
->whereHas('nodes', function (Builder $builder) use ($nodeId) {
$builder->where('id', $nodeId);
})
->whereHas('eggs', function (Builder $builder) use ($currentProductEggs) {
$builder->whereIn('id', $currentProductEggs);
})
->get()
->map(function ($product) use ($currentProduct, $pteroNode) {
$product->eggs = $product->eggs->pluck('name')->toArray();
Expand Down
38 changes: 38 additions & 0 deletions app/Http/Controllers/TermsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers;

use App\Settings\TermsSettings;
use Illuminate\Http\Request;

class TermsController extends Controller
{
public function index(Request $request, string $term)
{
$settings = app(TermsSettings::class);

switch ($term) {
case 'tos':
$title = __('Terms of Service');
$term = 'terms_of_service';
break;
case 'privacy':
$title = __('Privacy Policy');
$term = 'privacy_policy';
break;
case 'imprint':
$title = __('Imprint');
$term = 'imprint';
break;
default:
abort(404);
}

$content = $settings->$term;

return view('terms.index', [
'title' => $title,
'content' => $content,
]);
}
}
2 changes: 1 addition & 1 deletion app/Models/DiscordUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function addOrRemoveRole(string $action, string $role_id): mixed
'Content-Type' => 'application/json',
'X-Audit-Log-Reason' => 'Role removed by panel'
]
)->remove(
)->delete(
"https://discord.com/api/guilds/{$discordSettings->guild_id}/members/{$this->id}/roles/{$discordSettings->role_id}",
['access_token' => $discordSettings->bot_token]
),
Expand Down
21 changes: 5 additions & 16 deletions app/Notifications/InvoiceNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,18 @@
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use LaravelDaily\Invoices\Invoice;

class InvoiceNotification extends Notification implements ShouldQueue
{
use Queueable;

/**
* @var Invoice
*/
private $invoice;

private $invoice_file;
private $user;

private $payment;

/**
* Create a new notification instance.
*
* @param Invoice $invoice
*/
public function __construct(Invoice $invoice, User $user, Payment $payment)
public function __construct(string $invoice_file, User $user, Payment $payment)
{
$this->invoice = $invoice;
$this->invoice_file = $invoice_file;
$this->user = $user;
$this->payment = $payment;
}
Expand Down Expand Up @@ -58,12 +47,12 @@ public function toMail($notifiable)
->subject(__('Your Payment was successful!'))
->greeting(__('Hello').',')
->line(__('Your payment was processed successfully!'))
->line(__('Status').': '.$this->payment->status)
->line(__('Status').': '.$this->payment->status->value)
->line(__('Price').': '.$this->payment->formatToCurrency($this->payment->total_price))
->line(__('Type').': '.$this->payment->type)
->line(__('Amount').': '.$this->payment->amount)
->line(__('Balance').': '.number_format($this->user->credits, 2))
->line(__('User ID').': '.$this->payment->user_id)
->attach(storage_path('app/invoice/'.$this->user->id.'/'.now()->format('Y').'/'.$this->invoice->filename));
->attach(storage_path('app/invoice/'.$this->user->id.'/'.now()->format('Y').'/'.$this->invoice_file));
}
}
Loading

0 comments on commit 3e12163

Please sign in to comment.