fix: add fallback value for setting variables

This commit is contained in:
idevakk
2025-11-28 05:59:25 -08:00
parent a33c0dfa95
commit d4de074161
7 changed files with 88 additions and 50 deletions

View File

@@ -2,13 +2,13 @@
namespace App\Livewire\Frontend;
use Illuminate\Routing\Redirector;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Date;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use App\Models\Log;
use App\Models\ZEmail;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Date;
use Livewire\Component;
class Action extends Component
@@ -27,9 +27,12 @@ class Action extends Component
public $initial;
private $configSettings;
public function mount(): void
{
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
$this->configSettings = json_decode(config('app.settings.configuration_settings') ?: '{}');
$this->domains = $this->configSettings->domains ?? [];
$this->email = ZEmail::getEmail();
$this->emails = ZEmail::getEmails();
$this->validateDomainInEmail();
@@ -41,17 +44,17 @@ class Action extends Component
return $this->showAlert('error', __('Please enter Username'));
}
$this->checkDomainInUsername();
if (strlen((string) $this->username) < json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min || strlen((string) $this->username) > json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max) {
return $this->showAlert('error', __('Username length cannot be less than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min.' '.__('and greater than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max);
if (strlen((string) $this->username) < ($this->configSettings->custom_username_length_min ?? 3) || strlen((string) $this->username) > ($this->configSettings->custom_username_length_max ?? 30)) {
return $this->showAlert('error', __('Username length cannot be less than').' '.($this->configSettings->custom_username_length_min ?? 3).' '.__('and greater than').' '.($this->configSettings->custom_username_length_max ?? 30));
}
if (! $this->domain) {
return $this->showAlert('error', __('Please Select a Domain'));
}
if (in_array($this->username, json_decode((string) config('app.settings.configuration_settings'))->forbidden_ids)) {
if (in_array($this->username, $this->configSettings->forbidden_ids ?? [])) {
return $this->showAlert('error', __('Username not allowed'));
}
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of MAX ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail'));
return $this->showAlert('error', __('You have reached daily limit of MAX ').($this->configSettings->email_limit ?? 10).__(' temp mail'));
}
if (! $this->checkUsedEmail()) {
return $this->showAlert('error', __('Sorry! That email is already been used by someone else. Please try a different email address.'));
@@ -66,7 +69,7 @@ class Action extends Component
public function random()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomEmail();
@@ -76,7 +79,7 @@ class Action extends Component
public function gmail()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomGmail();
@@ -86,7 +89,7 @@ class Action extends Component
public function outlook()
{
if (! $this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.'));
return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.'));
}
$this->email = ZEmail::generateRandomOutlook();
@@ -100,7 +103,7 @@ class Action extends Component
private function showAlert(string $type, $message): void
{
$check = json_decode((string) config('app.settings.configuration_settings'))->email_limit;
$check = $this->configSettings->email_limit ?? 10;
if (str_contains((string) $message, (string) $check)) {
$this->dispatch('promotePremium');
}
@@ -110,13 +113,15 @@ class Action extends Component
private function checkEmailLimit(): bool
{
$logs = Log::query()->select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Date::now()->subDay())->groupBy('email')->groupBy('ip')->get();
return count($logs) < json_decode((string) config('app.settings.configuration_settings'))->email_limit;
return count($logs) < ($this->configSettings->email_limit ?? 10);
}
private function checkUsedEmail(): bool
{
if (json_decode((string) config('app.settings.configuration_settings'))->disable_used_email) {
if ($this->configSettings->disable_used_email ?? false) {
$check = Log::query()->where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count();
return $check <= 0;
}
@@ -139,11 +144,11 @@ class Action extends Component
$data = explode('@', (string) $this->email);
if (isset($data[1])) {
$domain = $data[1];
$domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
$domains = $this->configSettings->domains ?? [];
if (! in_array($domain, $domains)) {
$key = array_search($this->email, $this->emails);
ZEmail::removeEmail($this->email);
if ($key == 0 && count($this->emails) === 1 && json_decode((string) config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
if ($key == 0 && count($this->emails) === 1 && ($this->configSettings->after_last_email_delete ?? '') == 'redirect_to_homepage') {
to_route('home');
} else {
to_route('mailbox');