added bulk email generator
This commit is contained in:
142
app/Livewire/Dashboard/Bulk.php
Normal file
142
app/Livewire/Dashboard/Bulk.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Livewire\Component;
|
||||
use Session;
|
||||
|
||||
class Bulk extends Component
|
||||
{
|
||||
public $bulkEmails = [];
|
||||
public $bulkCount = 1;
|
||||
|
||||
private $isSubscribed = false;
|
||||
|
||||
public function mount() {
|
||||
$subscriptionCheck = auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id']);
|
||||
Session::put('isSubscribed', $subscriptionCheck);
|
||||
}
|
||||
public function generateBulk()
|
||||
{
|
||||
$this->validate([
|
||||
'bulkCount' => 'required|integer|min:1|max:500',
|
||||
]);
|
||||
|
||||
if (count($this->bulkEmails) > 0) {
|
||||
$this->bulkEmails = [];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->bulkCount; $i++) {
|
||||
$this->bulkEmails[] = $this->randomEmail();
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadBulk()
|
||||
{
|
||||
// Ensure there's something to download
|
||||
if (empty($this->bulkEmails) || !is_array($this->bulkEmails)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$filename = 'bulk_emails_' . now()->format('Ymd_His') . '.txt';
|
||||
$content = implode(PHP_EOL, $this->bulkEmails);
|
||||
|
||||
return response()->streamDownload(function () use ($content) {
|
||||
echo $content;
|
||||
}, $filename);
|
||||
}
|
||||
|
||||
private function randomEmail(): string
|
||||
{
|
||||
$domain = $this->getRandomDomain();
|
||||
if ($domain == "gmail.com" || $domain == "googlemail.com") {
|
||||
$uname = $this->getRandomGmailUser();
|
||||
$uname_len = strlen($uname);
|
||||
$len_power = $uname_len - 1;
|
||||
$combination = pow(2,$len_power);
|
||||
$rand_comb = mt_rand(1,$combination);
|
||||
$formatted = implode(' ',str_split($uname));
|
||||
$uname_exp = explode(' ', $formatted);
|
||||
|
||||
$bin = intval("");
|
||||
for($i=0; $i<$len_power; $i++) {
|
||||
$bin .= mt_rand(0,1);
|
||||
}
|
||||
$bin = explode(' ', implode(' ',str_split(strval($bin))));
|
||||
|
||||
$email = "";
|
||||
for($i=0; $i<$len_power; $i++) {
|
||||
$email .= $uname_exp[$i];
|
||||
if($bin[$i]) {
|
||||
$email .= ".";
|
||||
}
|
||||
}
|
||||
$email .= $uname_exp[$i];
|
||||
$gmail_rand = mt_rand(1,10);
|
||||
if($gmail_rand > 5) {
|
||||
$email .= "@gmail.com";
|
||||
} else {
|
||||
$email .= "@googlemail.com";
|
||||
}
|
||||
return $email;
|
||||
} else {
|
||||
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;
|
||||
if ($start == 0 && $end == 0) {
|
||||
return $this->generatePronounceableWord();
|
||||
}
|
||||
return $this->generatedRandomBetweenLength($start, $end);
|
||||
}
|
||||
private function generatedRandomBetweenLength($start, $end): string
|
||||
{
|
||||
$length = rand($start, $end);
|
||||
return $this->generateRandomString($length);
|
||||
}
|
||||
private function getRandomDomain() {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$count = count($domains);
|
||||
return $count > 0 ? $domains[rand(1, $count) - 1] : '';
|
||||
}
|
||||
private function getRandomGmailUser() {
|
||||
$gmailusername = json_decode(config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$count = count($gmailusername);
|
||||
return $count > 0 ? $gmailusername[rand(1, $count) - 1] : '';
|
||||
}
|
||||
private function generatePronounceableWord(): string
|
||||
{
|
||||
$c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones
|
||||
$v = 'aeiou'; //vowels
|
||||
$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)];
|
||||
}
|
||||
return $random;
|
||||
}
|
||||
private function generateRandomString($length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (Session::get('isSubscribed')) {
|
||||
return view('livewire.dashboard.bulk')->layout('components.layouts.dashboard');
|
||||
} else {
|
||||
return view('livewire.dashboard.not-subscribed')->layout('components.layouts.dashboard');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,9 +37,9 @@
|
||||
$navItems = [
|
||||
['label' => 'Dashboard', 'route' => 'dashboard'],
|
||||
['label' => 'Generate Premium Email', 'route' => 'dashboard.premium'],
|
||||
['label' => '10 Minute Mail', 'route' => 'dashboard.10minute'],
|
||||
['label' => 'Bulk Email', 'route' => 'dashboard.bulk'],
|
||||
['label' => 'Compose Email', 'route' => 'dashboard.compose'],
|
||||
//['label' => '10 Minute Mail', 'route' => 'dashboard.10minute'],
|
||||
['label' => 'Bulk Email Generator', 'route' => 'dashboard.bulk'],
|
||||
//['label' => 'Compose Email', 'route' => 'dashboard.compose'],
|
||||
];
|
||||
|
||||
$currentRoute = Route::currentRouteName();
|
||||
|
||||
49
resources/views/livewire/dashboard/bulk.blade.php
Normal file
49
resources/views/livewire/dashboard/bulk.blade.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<span>
|
||||
<div class="flex-1 overflow-hidden rounded-xl border border-neutral-200 dark:border-neutral-700 dark:bg-white/[0.03] sm:px-8 sm:py-8 lg:p-12 p-2">
|
||||
<div class="text-center">
|
||||
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-400 py-2">Bulk Email Generator</h2>
|
||||
<!-- Upper Part: Input + Button -->
|
||||
<div class="w-full max-w-xl mx-auto mb-2">
|
||||
<div class="flex rounded-lg overflow-hidden border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-zinc-800">
|
||||
<input
|
||||
type="number"
|
||||
max="500"
|
||||
wire:model="bulkCount"
|
||||
class="w-full px-4 py-2 bg-white dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 placeholder-zinc-500 focus:outline-none"
|
||||
placeholder="Enter a number (max 500)"
|
||||
oninput="this.value = Math.min(500, Math.max(0, parseInt(this.value) || ''))"
|
||||
/>
|
||||
<button
|
||||
wire:click="generateBulk"
|
||||
class="cursor-pointer px-5 py-2 bg-[#4361EE] text-white transition-colors dark:bg-[#4361EE] "
|
||||
>
|
||||
Generate
|
||||
</button>
|
||||
@if (!empty($bulkEmails))
|
||||
<button
|
||||
type="button"
|
||||
wire:click="downloadBulk"
|
||||
class="cursor-pointer px-5 py-2 bg-[#00AB55] text-white transition-colors dark:bg-[#00AB55] "
|
||||
>
|
||||
<flux:icon.download />
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
@error('bulkCount')
|
||||
<span class="text-sm text-red-600 dark:text-red-400">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
|
||||
@if(count($bulkEmails) > 0)
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
@foreach($bulkEmails as $email)
|
||||
<div class="truncate px-4 py-2 bg-white dark:bg-zinc-800 rounded shadow text-zinc-900 dark:text-zinc-100">
|
||||
{{ $email }}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
@@ -3,6 +3,7 @@
|
||||
use App\Http\Controllers\AppController;
|
||||
use App\Http\Middleware\CheckPageSlug;
|
||||
use App\Livewire\Blog;
|
||||
use App\Livewire\Dashboard\Bulk;
|
||||
use App\Livewire\Dashboard\Dashboard;
|
||||
use App\Livewire\Dashboard\Mailbox\Inbox;
|
||||
use App\Livewire\Frontend\Mailbox;
|
||||
@@ -47,7 +48,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
||||
Route::get('dashboard', Dashboard::class)->name('dashboard');
|
||||
Route::get('dashboard/generate-premium-email', Inbox::class)->name('dashboard.premium');
|
||||
Route::get('dashboard/generate-10minute-email', Dashboard::class)->name('dashboard.10minute');
|
||||
Route::get('dashboard/bulk-email-generator', Dashboard::class)->name('dashboard.bulk');
|
||||
Route::get('dashboard/bulk-email-generator', Bulk::class)->name('dashboard.bulk');
|
||||
Route::get('dashboard/compose-email', Dashboard::class)->name('dashboard.compose');
|
||||
|
||||
// Checkout Routes
|
||||
|
||||
Reference in New Issue
Block a user