chore: code refactor via rector
This commit is contained in:
@@ -2,17 +2,19 @@
|
||||
|
||||
namespace App\Livewire\Dashboard\Mailbox;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use App\ColorPicker;
|
||||
use App\Models\Log;
|
||||
use App\Models\Premium;
|
||||
use App\Models\PremiumEmail;
|
||||
use App\Models\UsageLog;
|
||||
use App\Models\ZEmail;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Session;
|
||||
|
||||
class Inbox extends Component
|
||||
{
|
||||
@@ -63,14 +65,14 @@ class Inbox extends Component
|
||||
$this->premium = Session::get('isInboxTypePremium', true);
|
||||
|
||||
if ($this->premium) {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->email = Premium::getEmail();
|
||||
$this->emails = Premium::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
} else {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
@@ -97,12 +99,12 @@ class Inbox extends Component
|
||||
$this->email_limit = $mailboxLimit;
|
||||
|
||||
} catch (Exception $e) {
|
||||
\Log::error($e->getMessage());
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->premium) {
|
||||
$mailboxHistory = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$mailboxHistory = UsageLog::query()->where(['user_id' => auth()->user()->id])->first();
|
||||
$this->mailboxHistory = $mailboxHistory->emails_created_history ?? [];
|
||||
} else {
|
||||
$this->mailboxHistory = ZEmail::getEmails() ?? [];
|
||||
@@ -112,27 +114,23 @@ class Inbox extends Component
|
||||
|
||||
private function checkMultipleEmails(): void
|
||||
{
|
||||
if (count($this->emails) == 0) {
|
||||
if (count($this->emails) === 0) {
|
||||
$this->emails = [$this->email];
|
||||
}
|
||||
if (count($this->emails) > 1) {
|
||||
$this->list = true;
|
||||
} else {
|
||||
$this->list = false;
|
||||
}
|
||||
$this->list = count($this->emails) > 1;
|
||||
}
|
||||
|
||||
public function switchEmail($email)
|
||||
{
|
||||
try {
|
||||
if ($email != null) {
|
||||
$data = explode('@', $email);
|
||||
$data = explode('@', (string) $email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
if ($this->premium) {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
} else {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
|
||||
}
|
||||
if (! in_array($domain, $domains)) {
|
||||
return $this->showAlert('error', __('This mailbox can not be recovered.'));
|
||||
@@ -140,17 +138,17 @@ class Inbox extends Component
|
||||
}
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
\Log::error($exception->getMessage());
|
||||
\Illuminate\Support\Facades\Log::error($exception->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->route('switchP', ['email' => $email]);
|
||||
return to_route('switchP', ['email' => $email]);
|
||||
}
|
||||
|
||||
public function syncEmail(): void
|
||||
{
|
||||
$this->email = Premium::getEmail();
|
||||
$this->emails = Premium::getEmails();
|
||||
if (count($this->emails) == 0) {
|
||||
if (count($this->emails) === 0) {
|
||||
$this->dispatch('getEmail');
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
@@ -174,13 +172,13 @@ class Inbox extends Component
|
||||
return $this->showAlert('error', __('Please enter Username'));
|
||||
}
|
||||
$this->checkDomainInUsername();
|
||||
if (strlen($this->username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($this->username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) {
|
||||
return $this->showAlert('error', __('Username length cannot be less than').' '.json_decode(config('app.settings.configuration_settings'))->custom_username_length_min.' '.__('and greater than').' '.json_decode(config('app.settings.configuration_settings'))->custom_username_length_max);
|
||||
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 (! $this->domain) {
|
||||
return $this->showAlert('error', __('Please Select a Domain'));
|
||||
}
|
||||
if (in_array($this->username, json_decode(config('app.settings.configuration_settings'))->forbidden_ids)) {
|
||||
if (in_array($this->username, json_decode((string) config('app.settings.configuration_settings'))->forbidden_ids)) {
|
||||
return $this->showAlert('error', __('Username not allowed'));
|
||||
}
|
||||
if (! $this->checkEmailLimit()) {
|
||||
@@ -195,7 +193,7 @@ class Inbox extends Component
|
||||
$this->email = ZEmail::createCustomEmail($this->username, $this->domain);
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.premium');
|
||||
return to_route('dashboard.premium');
|
||||
|
||||
}
|
||||
|
||||
@@ -205,13 +203,9 @@ class Inbox extends Component
|
||||
if (! $this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ').$this->email_limit.__(' temp mail addresses.'));
|
||||
}
|
||||
if ($this->premium) {
|
||||
$this->email = Premium::generateRandomEmail();
|
||||
} else {
|
||||
$this->email = ZEmail::generateRandomEmail();
|
||||
}
|
||||
$this->email = $this->premium ? Premium::generateRandomEmail() : ZEmail::generateRandomEmail();
|
||||
|
||||
return redirect()->route('dashboard.premium');
|
||||
return to_route('dashboard.premium');
|
||||
}
|
||||
|
||||
public function gmail()
|
||||
@@ -219,13 +213,9 @@ class Inbox extends Component
|
||||
if (! $this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ').$this->email_limit.__(' temp mail addresses.'));
|
||||
}
|
||||
if ($this->premium) {
|
||||
$this->email = Premium::generateRandomGmail();
|
||||
} else {
|
||||
$this->email = ZEmail::generateRandomGmail();
|
||||
}
|
||||
$this->email = $this->premium ? Premium::generateRandomGmail() : ZEmail::generateRandomGmail();
|
||||
|
||||
return redirect()->route('dashboard.premium');
|
||||
return to_route('dashboard.premium');
|
||||
}
|
||||
|
||||
public function outlook()
|
||||
@@ -239,38 +229,30 @@ class Inbox extends Component
|
||||
$this->email = ZEmail::generateRandomOutlook();
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.premium');
|
||||
return to_route('dashboard.premium');
|
||||
}
|
||||
|
||||
public function deleteEmail()
|
||||
public function deleteEmail(): Redirector|RedirectResponse
|
||||
{
|
||||
return redirect()->route('deleteP', ['email' => $this->email]);
|
||||
return to_route('deleteP', ['email' => $this->email]);
|
||||
}
|
||||
|
||||
private function showAlert($type, $message): void
|
||||
private function showAlert(string $type, $message): void
|
||||
{
|
||||
$this->dispatch('showAlert', ['type' => $type, 'message' => $message]);
|
||||
}
|
||||
|
||||
private function checkEmailLimit(): bool
|
||||
{
|
||||
$logs = Log::select('ip', 'email')->where('user_id', auth()->user()->id)->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get();
|
||||
if (count($logs) >= $this->email_limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
$logs = Log::query()->select('ip', 'email')->where('user_id', auth()->user()->id)->where('created_at', '>', Date::now()->subDay())->groupBy('email')->groupBy('ip')->get();
|
||||
return count($logs) < $this->email_limit;
|
||||
}
|
||||
|
||||
private function checkUsedEmail(): bool
|
||||
{
|
||||
if (json_decode(config('app.settings.configuration_settings'))->disable_used_email) {
|
||||
$check = Log::where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count();
|
||||
if ($check > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (json_decode((string) config('app.settings.configuration_settings'))->disable_used_email) {
|
||||
$check = Log::query()->where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count();
|
||||
return $check <= 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -278,7 +260,7 @@ class Inbox extends Component
|
||||
|
||||
private function checkDomainInUsername(): void
|
||||
{
|
||||
$parts = explode('@', $this->username);
|
||||
$parts = explode('@', (string) $this->username);
|
||||
if (isset($parts[1])) {
|
||||
if (in_array($parts[1], $this->domains)) {
|
||||
$this->domain = $parts[1];
|
||||
@@ -291,13 +273,13 @@ class Inbox extends Component
|
||||
{
|
||||
try {
|
||||
if ($this->email != null) {
|
||||
$data = explode('@', $this->email);
|
||||
$data = explode('@', (string) $this->email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
if ($this->premium) {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
} else {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
|
||||
}
|
||||
if (! in_array($domain, $domains)) {
|
||||
$key = array_search($this->email, $this->emails);
|
||||
@@ -306,16 +288,12 @@ class Inbox extends Component
|
||||
} else {
|
||||
ZEmail::removeEmail($this->email);
|
||||
}
|
||||
if ($key == 0 && count($this->emails) == 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
redirect()->route('dashboard.premium');
|
||||
} else {
|
||||
redirect()->route('dashboard.premium');
|
||||
}
|
||||
to_route('dashboard.premium');
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
\Log::error($exception->getMessage());
|
||||
\Illuminate\Support\Facades\Log::error($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +308,7 @@ class Inbox extends Component
|
||||
}
|
||||
$responses = [];
|
||||
if ($this->premium) {
|
||||
if (config('app.beta_feature') || ! json_decode(config('app.settings.imap_settings'))->premium_cc_check) {
|
||||
if (config('app.beta_feature') || ! json_decode((string) config('app.settings.imap_settings'))->premium_cc_check) {
|
||||
$responses = [
|
||||
'to' => Premium::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => [
|
||||
@@ -344,21 +322,19 @@ class Inbox extends Component
|
||||
'cc' => Premium::getMessages($this->email, 'cc', $this->deleted),
|
||||
];
|
||||
}
|
||||
} elseif (config('app.beta_feature') || ! json_decode((string) config('app.settings.imap_settings'))->cc_check) {
|
||||
$responses = [
|
||||
'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => [
|
||||
'data' => [],
|
||||
'notifications' => [],
|
||||
],
|
||||
];
|
||||
} else {
|
||||
if (config('app.beta_feature') || ! json_decode(config('app.settings.imap_settings'))->cc_check) {
|
||||
$responses = [
|
||||
'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => [
|
||||
'data' => [],
|
||||
'notifications' => [],
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$responses = [
|
||||
'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => ZEmail::getMessages($this->email, 'cc', $this->deleted),
|
||||
];
|
||||
}
|
||||
$responses = [
|
||||
'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => ZEmail::getMessages($this->email, 'cc', $this->deleted),
|
||||
];
|
||||
}
|
||||
|
||||
$this->deleted = [];
|
||||
@@ -366,7 +342,7 @@ class Inbox extends Component
|
||||
$notifications = array_merge($responses['to']['notifications'], $responses['cc']['notifications']);
|
||||
|
||||
if (count($notifications)) {
|
||||
if (! $this->overflow && count($this->messages) == $count) {
|
||||
if (! $this->overflow && count($this->messages) === $count) {
|
||||
$this->overflow = true;
|
||||
}
|
||||
} else {
|
||||
@@ -397,7 +373,7 @@ class Inbox extends Component
|
||||
$this->initial = true;
|
||||
}
|
||||
|
||||
public function delete($messageId)
|
||||
public function delete(string $messageId): void
|
||||
{
|
||||
|
||||
try {
|
||||
@@ -422,23 +398,23 @@ class Inbox extends Component
|
||||
|
||||
}
|
||||
|
||||
public function toggleMode()
|
||||
public function toggleMode(): void
|
||||
{
|
||||
$this->premium = ! $this->premium;
|
||||
Session::put('isInboxTypePremium', $this->premium);
|
||||
if ($this->premium) {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->email = Premium::getEmail();
|
||||
$this->emails = Premium::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
$mailboxHistory = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$mailboxHistory = UsageLog::query()->where(['user_id' => auth()->user()->id])->first();
|
||||
$this->mailboxHistory = $mailboxHistory->emails_created_history ?? [];
|
||||
$this->messages = [];
|
||||
|
||||
} else {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
@@ -453,17 +429,16 @@ class Inbox extends Component
|
||||
{
|
||||
if (Session::get('isSubscribed')) {
|
||||
return view('livewire.dashboard.mailbox.inbox')->layout('components.layouts.dashboard');
|
||||
} else {
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
|
||||
private function rrmdir($dir): void
|
||||
private function rrmdir(string $dir): void
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object != '.' && $object != '..') {
|
||||
if ($object !== '.' && $object !== '..') {
|
||||
if (is_dir($dir.DIRECTORY_SEPARATOR.$object) && ! is_link($dir.'/'.$object)) {
|
||||
$this->rrmdir($dir.DIRECTORY_SEPARATOR.$object);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user