Add all files

This commit is contained in:
root
2025-11-30 11:57:22 +01:00
parent 2ee51cac4f
commit 044271db3d
1476 changed files with 142544 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Livewire\Client;
use App\Livewire\ComponentWithProperties;
use Illuminate\Support\Facades\Auth;
class Account extends ComponentWithProperties
{
public string $first_name = '';
public string $last_name = '';
public string $email = '';
public function mount()
{
$user = Auth::user();
$this->first_name = $user->first_name;
$this->last_name = $user->last_name;
$this->email = $user->email;
$this->initializeProperties($user, $user::class);
}
public function rules()
{
return array_merge([
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'email' => 'required|email|max:255|unique:users,email,' . Auth::id(),
], $this->getRulesForProperties());
}
public function validationAttributes()
{
return $this->getAttributesForProperties();
}
public function submit()
{
$validatedData = $this->validate();
/** @var \App\Models\User $user */
$user = Auth::user();
$user->update($validatedData);
if (array_key_exists('properties', $validatedData)) {
$this->updateProperties($user, $validatedData['properties']);
}
$this->notify(__('Account updated successfully.'));
}
public function render()
{
return view('client.account.index')->layoutData([
'sidebar' => true,
]);
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace App\Livewire\Client;
use App\Exceptions\DisplayException;
use App\Helpers\ExtensionHelper;
use App\Livewire\Component;
use App\Models\Credit;
use App\Models\Gateway;
use App\Models\Invoice;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
class Credits extends Component
{
#[Validate('required|exists:currencies,code')]
public $currency;
public $amount;
#[Locked]
public $gateways;
public $gateway;
public function mount()
{
if (!config('settings.credits_enabled')) {
return redirect()->route('account');
}
$this->amount = config('settings.credits_minimum_deposit');
$this->currency = session('currency', config('settings.default_currency'));
$this->gateways = ExtensionHelper::getCheckoutGateways([], 'credits');
if (count($this->gateways) > 0 && !array_search($this->gateway, array_column($this->gateways, 'id')) !== false) {
$this->gateway = $this->gateways[0]->id;
}
}
public function addCredit()
{
$this->validate([
'currency' => 'required|exists:currencies,code',
'amount' => 'required|numeric|min:' . config('settings.credits_minimum_deposit') . '|max:' . config('settings.credits_maximum_deposit'),
'gateway' => 'required|in:' . implode(',', array_column($this->gateways, 'id')),
]);
if (Auth::user()->credits()->where('currency_code', $this->currency)->exists()) {
// Check if the current credits + the new credits exceed the maximum credits allowed
if (Auth::user()->credits()->where('currency_code', $this->currency)->sum('amount') + $this->amount > config('settings.credits_maximum_credit')) {
$this->notify('You cannot exceed the maximum credits allowed.', 'error');
return;
}
}
// Create invoice
DB::beginTransaction();
try {
$invoice = Invoice::create([
'user_id' => Auth::id(),
'currency_code' => $this->currency,
'due_at' => now(),
]);
$invoice->items()->create([
'description' => __('account.credit_deposit', ['currency' => $this->currency]),
'quantity' => 1,
'price' => $this->amount,
'reference_type' => Credit::class,
]);
DB::commit();
Session::put(['gateway' => $this->gateway]);
// Redirect to the invoices page and pay the invoice
if ($this->gateway) {
$pay = ExtensionHelper::pay(Gateway::where('id', $this->gateway)->first(), $invoice->fresh());
if (is_string($pay)) {
return $this->redirect($pay);
}
}
return $this->redirect(route('invoices.show', $invoice) . '?gateway=' . $this->gateway . '&pay', true);
} catch (\Exception $e) {
// Rollback the transaction
DB::rollBack();
// Return error message
// Is it a real error or a validation error?
// If it's a validation error, you can use the $this->addError() method to display the error message to the user.
if ($e instanceof DisplayException) {
$this->notify($e->getMessage(), 'error');
} else {
Log::error($e);
$this->notify('An error occurred while processing your order. Please try again later.');
}
throw $e;
}
}
public function render()
{
return view('client.account.credits')->layoutData([
'sidebar' => true,
]);
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Livewire\Client;
use App\Livewire\Component;
use App\Models\Session;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Attributes\Locked;
use RobThree\Auth\Providers\Qr\EndroidQrCodeProvider;
use RobThree\Auth\TwoFactorAuth;
class Security extends Component
{
public string $current_password = '';
public string $password = '';
public string $password_confirmation = '';
public bool $twoFactorEnabled = false;
#[Locked]
public $twoFactorData = [];
#[Locked]
public $showEnableTwoFactor = false;
public string $twoFactorCode = '';
public function mount()
{
$this->twoFactorEnabled = Auth::user()->tfa_secret ? true : false;
}
public function rules()
{
return [
'current_password' => 'required|string',
'password' => 'required|string|min:8|confirmed',
];
}
public function changePassword()
{
$this->validate();
if (!Hash::check($this->current_password, Auth::user()->password)) {
return $this->notify(__('account.notifications.password_incorrect'), 'error');
}
Auth::user()->update([
'password' => Hash::make($this->password),
]);
$this->notify(__('account.notifications.password_changed'));
$this->reset('current_password', 'password', 'password_confirmation');
}
public function enableTwoFactor()
{
if ($this->showEnableTwoFactor) {
$this->validate([
'twoFactorCode' => 'required|string',
]);
$tfa = new TwoFactorAuth(new EndroidQrCodeProvider, config('app.name'));
if ($tfa->verifyCode($this->twoFactorData['secret'], $this->twoFactorCode)) {
Auth::user()->update([
'tfa_secret' => $this->twoFactorData['secret'],
]);
$this->notify(__('account.notifications.two_factor_enabled'));
$this->twoFactorEnabled = true;
$this->showEnableTwoFactor = false;
} else {
$this->notify(__('account.notifications.two_factor_code_incorrect'), 'error');
}
} else {
$tfa = new TwoFactorAuth(new EndroidQrCodeProvider, config('app.name'));
$secret = $tfa->createSecret();
$this->twoFactorData = [
'secret' => $secret,
'image' => $tfa->getQRCodeImageAsDataUri(Auth::user()->email, $secret),
];
$this->showEnableTwoFactor = true;
}
}
public function disableTwoFactor()
{
Auth::user()->update([
'tfa_secret' => null,
]);
$this->notify(__('account.notifications.two_factor_disabled'));
$this->twoFactorEnabled = false;
}
public function logoutSession(Session $session)
{
$session->delete();
$this->notify(__('account.notifications.session_logged_out'));
}
public function render()
{
return view('client.account.security')->layoutData([
'sidebar' => true,
]);
}
}