chore: code refactor via rector
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Livewire\Component;
|
||||
use Session;
|
||||
|
||||
class Bulk extends Component
|
||||
{
|
||||
@@ -11,15 +11,13 @@ class Bulk extends Component
|
||||
|
||||
public $bulkCount = 1;
|
||||
|
||||
private $isSubscribed = false;
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$subscriptionCheck = auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id']);
|
||||
Session::put('isSubscribed', $subscriptionCheck);
|
||||
}
|
||||
|
||||
public function generateBulk()
|
||||
public function generateBulk(): void
|
||||
{
|
||||
$this->validate([
|
||||
'bulkCount' => 'required|integer|min:1|max:500',
|
||||
@@ -44,7 +42,7 @@ class Bulk extends Component
|
||||
$filename = 'bulk_emails_'.now()->format('Ymd_His').'.txt';
|
||||
$content = implode(PHP_EOL, $this->bulkEmails);
|
||||
|
||||
return response()->streamDownload(function () use ($content) {
|
||||
return response()->streamDownload(function () use ($content): void {
|
||||
echo $content;
|
||||
}, $filename);
|
||||
}
|
||||
@@ -54,11 +52,11 @@ class Bulk extends Component
|
||||
$domain = $this->getRandomDomain();
|
||||
if ($domain == 'gmail.com' || $domain == 'googlemail.com') {
|
||||
$uname = $this->getRandomGmailUser();
|
||||
$uname_len = strlen($uname);
|
||||
$uname_len = strlen((string) $uname);
|
||||
$len_power = $uname_len - 1;
|
||||
$combination = pow(2, $len_power);
|
||||
$combination = 2 ** $len_power;
|
||||
$rand_comb = mt_rand(1, $combination);
|
||||
$formatted = implode(' ', str_split($uname));
|
||||
$formatted = implode(' ', str_split((string) $uname));
|
||||
$uname_exp = explode(' ', $formatted);
|
||||
|
||||
$bin = intval('');
|
||||
@@ -70,7 +68,7 @@ class Bulk extends Component
|
||||
$email = '';
|
||||
for ($i = 0; $i < $len_power; $i++) {
|
||||
$email .= $uname_exp[$i];
|
||||
if ($bin[$i]) {
|
||||
if ($bin[$i] !== '' && $bin[$i] !== '0') {
|
||||
$email .= '.';
|
||||
}
|
||||
}
|
||||
@@ -83,15 +81,14 @@ class Bulk extends Component
|
||||
}
|
||||
|
||||
return $email;
|
||||
} else {
|
||||
return $this->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
return $this->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
|
||||
private function generateRandomUsername(): string
|
||||
{
|
||||
$start = json_decode(config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode(config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
$start = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
if ($start == 0 && $end == 0) {
|
||||
return $this->generatePronounceableWord();
|
||||
}
|
||||
@@ -101,25 +98,25 @@ class Bulk extends Component
|
||||
|
||||
private function generatedRandomBetweenLength($start, $end): string
|
||||
{
|
||||
$length = rand($start, $end);
|
||||
$length = random_int($start, $end);
|
||||
|
||||
return $this->generateRandomString($length);
|
||||
}
|
||||
|
||||
private function getRandomDomain()
|
||||
{
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$count = count($domains);
|
||||
|
||||
return $count > 0 ? $domains[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $domains[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function getRandomGmailUser()
|
||||
{
|
||||
$gmailusername = json_decode(config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$gmailusername = json_decode((string) config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$count = count($gmailusername);
|
||||
|
||||
return $count > 0 ? $gmailusername[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $gmailusername[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function generatePronounceableWord(): string
|
||||
@@ -129,21 +126,21 @@ class Bulk extends Component
|
||||
$a = $c.$v; // both
|
||||
$random = '';
|
||||
for ($j = 0; $j < 2; $j++) {
|
||||
$random .= $c[rand(0, strlen($c) - 1)];
|
||||
$random .= $v[rand(0, strlen($v) - 1)];
|
||||
$random .= $a[rand(0, strlen($a) - 1)];
|
||||
$random .= $c[random_int(0, strlen($c) - 1)];
|
||||
$random .= $v[random_int(0, strlen($v) - 1)];
|
||||
$random .= $a[random_int(0, strlen($a) - 1)];
|
||||
}
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10): string
|
||||
private function generateRandomString(int $length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
@@ -153,8 +150,7 @@ class Bulk extends Component
|
||||
{
|
||||
if (Session::get('isSubscribed')) {
|
||||
return view('livewire.dashboard.bulk')->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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Livewire\Component;
|
||||
use Session;
|
||||
|
||||
class BulkGmail extends Component
|
||||
{
|
||||
@@ -13,7 +13,7 @@ class BulkGmail extends Component
|
||||
|
||||
public $bulkEmails = [];
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$subscriptionCheck = auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id']);
|
||||
Session::put('isSubscribed', $subscriptionCheck);
|
||||
@@ -34,7 +34,7 @@ class BulkGmail extends Component
|
||||
$this->bulkEmails = [];
|
||||
}
|
||||
|
||||
$this->bulkEmails = $this->generateDotVariants(explode('@', $this->email)[0], $this->quantity);
|
||||
$this->bulkEmails = $this->generateDotVariants(explode('@', (string) $this->email)[0], $this->quantity);
|
||||
}
|
||||
|
||||
public function downloadBulk()
|
||||
@@ -47,12 +47,15 @@ class BulkGmail extends Component
|
||||
$filename = 'bulk_gmails_'.now()->format('Ymd_His').'.txt';
|
||||
$content = implode(PHP_EOL, $this->bulkEmails);
|
||||
|
||||
return response()->streamDownload(function () use ($content) {
|
||||
return response()->streamDownload(function () use ($content): void {
|
||||
echo $content;
|
||||
}, $filename);
|
||||
}
|
||||
|
||||
private function generateDotVariants($uname, $quantity)
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function generateDotVariants(string $uname, int $quantity): array
|
||||
{
|
||||
$length = strlen($uname);
|
||||
$positions = range(1, $length - 1);
|
||||
@@ -89,7 +92,7 @@ class BulkGmail extends Component
|
||||
return [[]];
|
||||
}
|
||||
|
||||
if (empty($items)) {
|
||||
if ($items === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -102,19 +105,14 @@ class BulkGmail extends Component
|
||||
$combinations[] = $c;
|
||||
}
|
||||
|
||||
foreach ($this->combinations($tail, $size) as $c) {
|
||||
$combinations[] = $c;
|
||||
}
|
||||
|
||||
return $combinations;
|
||||
return $this->combinations($tail, $size);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (Session::get('isSubscribed')) {
|
||||
return view('livewire.dashboard.bulk-gmail')->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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\UsageLog;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Component;
|
||||
use Log;
|
||||
use Stripe\StripeClient;
|
||||
|
||||
class Dashboard extends Component
|
||||
@@ -27,13 +27,13 @@ class Dashboard extends Component
|
||||
public function paymentStatus(Request $request)
|
||||
{
|
||||
$status = $request->route('status');
|
||||
$currentUrl = $request->fullUrl();
|
||||
$request->fullUrl();
|
||||
if ($status == 'success') {
|
||||
$this->syncSubscription();
|
||||
|
||||
return redirect()->route('dashboard')->with('status', 'success');
|
||||
} elseif ($status == 'cancel') {
|
||||
return redirect()->route('dashboard')->with('status', 'cancel');
|
||||
return to_route('dashboard')->with('status', 'success');
|
||||
}
|
||||
if ($status == 'cancel') {
|
||||
return to_route('dashboard')->with('status', 'cancel');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,17 +63,15 @@ class Dashboard extends Component
|
||||
$canceled_at = $subscriptionData->canceled_at;
|
||||
$status = $subscriptionData->status;
|
||||
if ($cancel_at_period_end) {
|
||||
$final_ends_at = Carbon::createFromTimestamp($cancel_at)->toDateTimeString();
|
||||
$final_ends_at = Date::createFromTimestamp($cancel_at)->toDateTimeString();
|
||||
} elseif ($cancel_at === null && $canceled_at !== null && $status === 'canceled' && $cancel_at_period_end === false) {
|
||||
// $final_ends_at = Carbon::createFromTimestamp($canceled_at)->toDateTimeString();
|
||||
$final_ends_at = Date::now()->subDays(2)->toDateTimeString();
|
||||
$redirect = true;
|
||||
} elseif ($status === 'active' && $cancel_at !== null) {
|
||||
$final_ends_at = Date::createFromTimestamp($cancel_at)->toDateTimeString();
|
||||
} else {
|
||||
if ($cancel_at === null && $canceled_at !== null && $status === 'canceled' && $cancel_at_period_end === false) {
|
||||
// $final_ends_at = Carbon::createFromTimestamp($canceled_at)->toDateTimeString();
|
||||
$final_ends_at = Carbon::now()->subDays(2)->toDateTimeString();
|
||||
$redirect = true;
|
||||
} elseif ($status === 'active' && $cancel_at !== null) {
|
||||
$final_ends_at = Carbon::createFromTimestamp($cancel_at)->toDateTimeString();
|
||||
} else {
|
||||
$final_ends_at = null;
|
||||
}
|
||||
$final_ends_at = null;
|
||||
}
|
||||
|
||||
DB::table('subscriptions')
|
||||
@@ -81,7 +79,7 @@ class Dashboard extends Component
|
||||
->update([
|
||||
'stripe_status' => $status,
|
||||
'ends_at' => $final_ends_at,
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Date::now()->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -117,11 +115,7 @@ class Dashboard extends Component
|
||||
$stripe_product = $items->price->product;
|
||||
$ends_at = $items->current_period_end;
|
||||
$subscriptionItemId = $items->id;
|
||||
if ($cancel_at_period_end) {
|
||||
$final_ends_at = Carbon::createFromTimestamp($ends_at)->toDateTimeString();
|
||||
} else {
|
||||
$final_ends_at = null;
|
||||
}
|
||||
$final_ends_at = $cancel_at_period_end ? Date::createFromTimestamp($ends_at)->toDateTimeString() : null;
|
||||
|
||||
try {
|
||||
if ($status === 'active') {
|
||||
@@ -135,8 +129,8 @@ class Dashboard extends Component
|
||||
'stripe_price' => $stripe_price,
|
||||
'quantity' => $quantity,
|
||||
'ends_at' => $final_ends_at,
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
'created_at' => Date::now()->toDateTimeString(),
|
||||
'updated_at' => Date::now()->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$subscriptionsTable = DB::table('subscriptions')->where(['stripe_id' => $subscriptionId])->first();
|
||||
@@ -149,8 +143,8 @@ class Dashboard extends Component
|
||||
'stripe_product' => $stripe_product,
|
||||
'stripe_price' => $stripe_price,
|
||||
'quantity' => $quantity,
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
'created_at' => Date::now()->toDateTimeString(),
|
||||
'updated_at' => Date::now()->toDateTimeString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +159,7 @@ class Dashboard extends Component
|
||||
public function mount(Request $request)
|
||||
{
|
||||
if ($this->checkForSubscriptionStatus()) {
|
||||
return redirect()->route('dashboard');
|
||||
return to_route('dashboard');
|
||||
}
|
||||
try {
|
||||
$status = $request->session()->get('status');
|
||||
@@ -177,7 +171,7 @@ class Dashboard extends Component
|
||||
}
|
||||
$request->session()->forget('status');
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
} catch (Exception) {
|
||||
|
||||
}
|
||||
|
||||
@@ -207,7 +201,7 @@ class Dashboard extends Component
|
||||
}
|
||||
}
|
||||
|
||||
$usageLog = UsageLog::where('user_id', auth()->user()->id)->first();
|
||||
$usageLog = UsageLog::query()->where('user_id', auth()->user()->id)->first();
|
||||
$this->usageLog = [
|
||||
'emails_created_count' => $usageLog->emails_created_count ?? 0,
|
||||
'emails_received_count' => $usageLog->emails_received_count ?? 0,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use App\Models\ActivationKey;
|
||||
use App\Models\Plan;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Log;
|
||||
|
||||
class Pricing extends Component
|
||||
{
|
||||
@@ -34,8 +36,8 @@ class Pricing extends Component
|
||||
'activation_key.max' => 'The activation key must not exceed 30 characters.',
|
||||
]);
|
||||
|
||||
$trimmedKey = trim($this->activation_key);
|
||||
$activation = ActivationKey::where('activation_key', $trimmedKey)
|
||||
$trimmedKey = trim((string) $this->activation_key);
|
||||
$activation = ActivationKey::query()->where('activation_key', $trimmedKey)
|
||||
->where('is_activated', false)
|
||||
->first();
|
||||
|
||||
@@ -43,7 +45,7 @@ class Pricing extends Component
|
||||
if ($activation->price_id !== null) {
|
||||
$result = $this->addSubscription($activation->price_id);
|
||||
}
|
||||
if ($result === true) {
|
||||
if ($result) {
|
||||
$activation->is_activated = true;
|
||||
$activation->user_id = auth()->id();
|
||||
$activation->save();
|
||||
@@ -61,7 +63,7 @@ class Pricing extends Component
|
||||
private function addSubscription($price_id): bool
|
||||
{
|
||||
try {
|
||||
$plan = Plan::where('pricing_id', $price_id)->firstOrFail();
|
||||
$plan = Plan::query()->where('pricing_id', $price_id)->firstOrFail();
|
||||
$user = auth()->user();
|
||||
$user->createOrGetStripeCustomer();
|
||||
$user->updateStripeCustomer([
|
||||
@@ -76,11 +78,7 @@ class Pricing extends Component
|
||||
$balance = $user->balance();
|
||||
$user->newSubscription('default', $plan->pricing_id)->create();
|
||||
|
||||
if ($plan->monthly_billing == 1) {
|
||||
$ends_at = now()->addMonth();
|
||||
} else {
|
||||
$ends_at = now()->addYear();
|
||||
}
|
||||
$ends_at = $plan->monthly_billing == 1 ? now()->addMonth() : now()->addYear();
|
||||
$user->subscription('default')->cancelAt($ends_at);
|
||||
|
||||
return true;
|
||||
@@ -91,7 +89,7 @@ class Pricing extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
public function render(): Factory|View
|
||||
{
|
||||
return view('livewire.dashboard.pricing');
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketResponse;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Request;
|
||||
use Str;
|
||||
|
||||
class Support extends Component
|
||||
{
|
||||
@@ -25,7 +25,7 @@ class Support extends Component
|
||||
|
||||
public $closed = 0;
|
||||
|
||||
public function store()
|
||||
public function store(): void
|
||||
{
|
||||
$this->validate([
|
||||
'subject' => 'required|string|max:255',
|
||||
@@ -33,7 +33,7 @@ class Support extends Component
|
||||
]);
|
||||
|
||||
try {
|
||||
$ticket = Ticket::create([
|
||||
$ticket = Ticket::query()->create([
|
||||
'user_id' => auth()->id(),
|
||||
'ticket_id' => strtoupper(Str::random(6)),
|
||||
'subject' => $this->subject,
|
||||
@@ -47,13 +47,13 @@ class Support extends Component
|
||||
$this->tickets = Ticket::with('responses')
|
||||
->where('user_id', auth()->id())
|
||||
->get();
|
||||
} catch (Exception $exception) {
|
||||
} catch (Exception) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Something went wrong!']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function reply($ticket_id)
|
||||
public function reply($ticket_id): void
|
||||
{
|
||||
$this->validate([
|
||||
'response' => 'required|string',
|
||||
@@ -67,14 +67,14 @@ class Support extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$ticket = Ticket::find($ticket_id);
|
||||
$ticket = Ticket::query()->find($ticket_id);
|
||||
if (! $ticket) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Ticket not found.']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TicketResponse::create([
|
||||
TicketResponse::query()->create([
|
||||
'ticket_id' => $ticket_id,
|
||||
'user_id' => auth()->id(),
|
||||
'response' => $this->response,
|
||||
@@ -90,20 +90,20 @@ class Support extends Component
|
||||
->where('user_id', auth()->id())
|
||||
->get();
|
||||
|
||||
} catch (Exception $exception) {
|
||||
} catch (Exception) {
|
||||
session()->flash('error', 'Something went wrong!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function close($ticket_id)
|
||||
public function close($ticket_id): void
|
||||
{
|
||||
if (! is_numeric($ticket_id)) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Invalid ticket ID.']);
|
||||
|
||||
return;
|
||||
}
|
||||
$ticket = Ticket::find($ticket_id);
|
||||
$ticket = Ticket::query()->find($ticket_id);
|
||||
if (! $ticket) {
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Ticket not found.']);
|
||||
|
||||
@@ -119,7 +119,7 @@ class Support extends Component
|
||||
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'This ticket has been closed!']);
|
||||
}
|
||||
|
||||
public function mount()
|
||||
public function mount(): void
|
||||
{
|
||||
$this->tickets = Ticket::with('responses')
|
||||
->where('user_id', auth()->id())
|
||||
@@ -127,15 +127,11 @@ class Support extends Component
|
||||
$this->updateTicketCounts();
|
||||
}
|
||||
|
||||
public function updateTicketCounts()
|
||||
public function updateTicketCounts(): void
|
||||
{
|
||||
$this->open = $this->tickets->filter(function ($ticket) {
|
||||
return in_array($ticket->status, ['open', 'pending']);
|
||||
})->count();
|
||||
$this->open = $this->tickets->filter(fn($ticket): bool => in_array($ticket->status, ['open', 'pending']))->count();
|
||||
|
||||
$this->closed = $this->tickets->filter(function ($ticket) {
|
||||
return $ticket->status === 'closed';
|
||||
})->count();
|
||||
$this->closed = $this->tickets->filter(fn($ticket): bool => $ticket->status === 'closed')->count();
|
||||
}
|
||||
|
||||
protected function getClientIp()
|
||||
|
||||
Reference in New Issue
Block a user