added email notification for TicketResource.php, add option to edit users - ban, unban
This commit is contained in:
@@ -198,6 +198,30 @@ class TicketResource extends Resource
|
|||||||
->bulkActions([
|
->bulkActions([
|
||||||
Tables\Actions\BulkActionGroup::make([
|
Tables\Actions\BulkActionGroup::make([
|
||||||
Tables\Actions\DeleteBulkAction::make(),
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
Tables\Actions\BulkAction::make('notify_users')
|
||||||
|
->label('Send Email Notification')
|
||||||
|
->color('success')
|
||||||
|
->icon('heroicon-o-envelope')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->deselectRecordsAfterCompletion()
|
||||||
|
->action(function (\Illuminate\Support\Collection $records) {
|
||||||
|
foreach ($records as $ticket) {
|
||||||
|
$responses = $ticket->responses()
|
||||||
|
->with('user')
|
||||||
|
->orderBy('created_at', 'desc')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
if ($ticket->user && $ticket->user->email) {
|
||||||
|
\Illuminate\Support\Facades\Mail::to($ticket->user->email)
|
||||||
|
->send(new \App\Mail\TicketResponseNotification($ticket, $responses));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
\Filament\Notifications\Notification::make()
|
||||||
|
->title('Email notifications sent successfully!')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
159
app/Filament/Resources/UserResource.php
Normal file
159
app/Filament/Resources/UserResource.php
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Resources\UserResource\Pages;
|
||||||
|
use App\Models\User;
|
||||||
|
use DB;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\DatePicker;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Columns\BadgeColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
|
||||||
|
class UserResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = User::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
TextInput::make('name')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
|
||||||
|
TextInput::make('email')
|
||||||
|
->email()
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
|
||||||
|
TextInput::make('stripe_id')
|
||||||
|
->label('Stripe ID')
|
||||||
|
->disabled()
|
||||||
|
->helperText('Automatically managed by Stripe'),
|
||||||
|
|
||||||
|
TextInput::make('pm_type')
|
||||||
|
->label('Payment Method Type')
|
||||||
|
->disabled(),
|
||||||
|
|
||||||
|
TextInput::make('pm_last_four')
|
||||||
|
->label('Card Last 4 Digits')
|
||||||
|
->disabled(),
|
||||||
|
|
||||||
|
DatePicker::make('trial_ends_at')
|
||||||
|
->label('Trial Ends At')
|
||||||
|
->disabled()
|
||||||
|
->displayFormat('Y-m-d H:i:s'),
|
||||||
|
Select::make('level')
|
||||||
|
->label('User Level')
|
||||||
|
->options([
|
||||||
|
0 => 'Normal User',
|
||||||
|
1 => 'Banned',
|
||||||
|
9 => 'Super Admin',
|
||||||
|
])
|
||||||
|
->required(),
|
||||||
|
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('name')->sortable()->searchable(),
|
||||||
|
TextColumn::make('email')->sortable()->searchable(),
|
||||||
|
BadgeColumn::make('level')
|
||||||
|
->label('User Level')
|
||||||
|
->getStateUsing(function ($record) {
|
||||||
|
return match ($record->level) {
|
||||||
|
0 => 'Normal User',
|
||||||
|
1 => 'Banned',
|
||||||
|
9 => 'Super Admin',
|
||||||
|
default => 'Unknown', // In case some invalid level exists
|
||||||
|
};
|
||||||
|
})
|
||||||
|
->colors([
|
||||||
|
'success' => fn ($state) => $state === 'Normal User',
|
||||||
|
'danger' => fn ($state) => $state === 'Banned',
|
||||||
|
'warning' => fn ($state) => $state === 'Super Admin',
|
||||||
|
])
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('stripe_id')->label('Stripe ID')->copyable(),
|
||||||
|
TextColumn::make('pm_last_four')->label('Card Last 4'),
|
||||||
|
TextColumn::make('trial_ends_at')->label('Trial Ends')->dateTime()->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->filters([
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
Tables\Actions\BulkAction::make('updateLevel')
|
||||||
|
->label('Update User Level')
|
||||||
|
->action(function (Collection $records, array $data) {
|
||||||
|
|
||||||
|
$newLevel = $data['new_level'];
|
||||||
|
if ($newLevel === 9) {
|
||||||
|
throw new \Exception('User level cannot be 9 or higher.');
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('users')
|
||||||
|
->whereIn('id', $records->pluck('id'))
|
||||||
|
->update(['level' => $newLevel]);
|
||||||
|
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('User Level Updated')
|
||||||
|
->body('The selected users\' levels have been updated successfully.')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
})
|
||||||
|
->icon('heroicon-o-pencil')
|
||||||
|
->color('primary')
|
||||||
|
->modalHeading('Select User Level')
|
||||||
|
->modalSubheading('Please choose the user level to apply to the selected users.')
|
||||||
|
->form([
|
||||||
|
Select::make('new_level')
|
||||||
|
->label('Select User Level')
|
||||||
|
->options([
|
||||||
|
0 => 'Unban (Normal User)',
|
||||||
|
1 => 'Ban',
|
||||||
|
])
|
||||||
|
->required(),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListUsers::route('/'),
|
||||||
|
'create' => Pages\CreateUser::route('/create'),
|
||||||
|
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/Filament/Resources/UserResource/Pages/CreateUser.php
Normal file
12
app/Filament/Resources/UserResource/Pages/CreateUser.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\UserResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\UserResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateUser extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = UserResource::class;
|
||||||
|
}
|
||||||
19
app/Filament/Resources/UserResource/Pages/EditUser.php
Normal file
19
app/Filament/Resources/UserResource/Pages/EditUser.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\UserResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\UserResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditUser extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = UserResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/UserResource/Pages/ListUsers.php
Normal file
19
app/Filament/Resources/UserResource/Pages/ListUsers.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\UserResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\UserResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListUsers extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = UserResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Http/Middleware/CheckUserBanned.php
Normal file
25
app/Http/Middleware/CheckUserBanned.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class CheckUserBanned
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
if (Auth::check() && Auth::user()->level === 1) {
|
||||||
|
// Return the banned page instead of proceeding with the request
|
||||||
|
return response()->view('banned');
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
app/Mail/TicketResponseNotification.php
Normal file
59
app/Mail/TicketResponseNotification.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use App\Models\Ticket;
|
||||||
|
use App\Models\TicketResponse;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Content;
|
||||||
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class TicketResponseNotification extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public Ticket $ticket;
|
||||||
|
public Collection $responses;
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*/
|
||||||
|
public function __construct(Ticket $ticket, Collection $responses)
|
||||||
|
{
|
||||||
|
$this->ticket = $ticket;
|
||||||
|
$this->responses = $responses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message envelope.
|
||||||
|
*/
|
||||||
|
public function envelope(): Envelope
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
subject: 'Support Ticket Response: #'. $this->ticket->ticket_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
markdown: 'emails.ticket.response',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||||
|
*/
|
||||||
|
public function attachments(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
43
resources/views/banned.blade.php
Normal file
43
resources/views/banned.blade.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" class="dark">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>Account Banned</title>
|
||||||
|
<link rel="icon" type="image/png" href="{{ asset('images/logo.webp') }}">
|
||||||
|
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
||||||
|
</head>
|
||||||
|
<body class="bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-white font-sans antialiased">
|
||||||
|
|
||||||
|
<div class="min-h-screen flex flex-col justify-center items-center py-12 px-6 sm:px-8">
|
||||||
|
<div class="text-center max-w-xl">
|
||||||
|
<!-- Circular Cross Ban Icon -->
|
||||||
|
<svg class="w-20 h-20 text-red-500 dark:text-red-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" fill="none"/>
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 6l12 12M18 6L6 18"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
<h1 class="mt-6 text-lg font-bold text-red-400 dark:text-red-400">Account Access Restricted</h1>
|
||||||
|
<p class="mt-4 text-md text-gray-700 dark:text-gray-300">
|
||||||
|
We regret to inform you that your account has been temporarily banned due to potential abuse detected by our system.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="mt-6 space-y-4">
|
||||||
|
<p class="text-md text-gray-600 dark:text-gray-300">
|
||||||
|
If you believe this is a mistake, please reach out to us for assistance.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<flux:button as="a" href="mailto:contact@zemail.me">
|
||||||
|
Contact Support
|
||||||
|
</flux:button>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="text-sm text-gray-500 dark:text-gray-400">
|
||||||
|
Or email us at <a href="mailto:contact@zemail.me" class="underline text-blue-500">contact@zemail.me</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
26
resources/views/emails/ticket/response.blade.php
Normal file
26
resources/views/emails/ticket/response.blade.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<x-mail::message>
|
||||||
|
# Support Ticket Response : #{{ $ticket->ticket_id }}
|
||||||
|
|
||||||
|
**Subject:** {{ $ticket->subject }}
|
||||||
|
|
||||||
|
**Message:**
|
||||||
|
{{ $ticket->message }}
|
||||||
|
|
||||||
|
|
||||||
|
@foreach ($responses as $response)
|
||||||
|
**Response from {{ $response->user_id === 1 ? 'Support Team' : $response->user->name }} ({{ $response->created_at->diffForHumans() }}):**
|
||||||
|
|
||||||
|
> {{ $response->response }}
|
||||||
|
|
||||||
|
@if (!$loop->last)
|
||||||
|
---
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
<x-mail::button :url="route('dashboard.support')">
|
||||||
|
View Ticket
|
||||||
|
</x-mail::button>
|
||||||
|
|
||||||
|
Thanks,<br>
|
||||||
|
{{ config('app.name') }}
|
||||||
|
</x-mail::message>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\AppController;
|
use App\Http\Controllers\AppController;
|
||||||
use App\Http\Middleware\CheckPageSlug;
|
use App\Http\Middleware\CheckPageSlug;
|
||||||
|
use App\Http\Middleware\CheckUserBanned;
|
||||||
use App\Livewire\AddOn;
|
use App\Livewire\AddOn;
|
||||||
use App\Livewire\Blog;
|
use App\Livewire\Blog;
|
||||||
use App\Livewire\Dashboard\Bulk;
|
use App\Livewire\Dashboard\Bulk;
|
||||||
@@ -54,7 +55,7 @@ Route::get('gmailnator', AddOn::class)->name('gmailnator');
|
|||||||
Route::get('emailnator', AddOn::class)->name('emailnator');
|
Route::get('emailnator', AddOn::class)->name('emailnator');
|
||||||
Route::get('temp-gmail', AddOn::class)->name('temp-gmail');
|
Route::get('temp-gmail', AddOn::class)->name('temp-gmail');
|
||||||
|
|
||||||
Route::middleware(['auth', 'verified'])->group(function () {
|
Route::middleware(['auth', 'verified', CheckUserBanned::class])->group(function () {
|
||||||
Route::get('dashboard', Dashboard::class)->name('dashboard');
|
Route::get('dashboard', Dashboard::class)->name('dashboard');
|
||||||
Route::get('dashboard/generate-premium-email', Inbox::class)->name('dashboard.premium');
|
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/generate-10minute-email', Dashboard::class)->name('dashboard.10minute');
|
||||||
@@ -111,7 +112,28 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => trim($output),
|
'message' => trim($output),
|
||||||
]);
|
]);
|
||||||
});
|
})->name('storageLink');
|
||||||
|
|
||||||
|
Route::get('0xdash/scache', function (Request $request) {
|
||||||
|
$validUser = 'admin';
|
||||||
|
$validPass = 'admin@9608'; // 🔐 Change this to something secure
|
||||||
|
|
||||||
|
if (!isset($_SERVER['PHP_AUTH_USER']) ||
|
||||||
|
$_SERVER['PHP_AUTH_USER'] !== $validUser ||
|
||||||
|
$_SERVER['PHP_AUTH_PW'] !== $validPass) {
|
||||||
|
|
||||||
|
header('WWW-Authenticate: Basic realm="Restricted Area"');
|
||||||
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
echo 'Unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
Artisan::call('cache:clear');
|
||||||
|
$output = Artisan::output();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => trim($output),
|
||||||
|
]);
|
||||||
|
})->name('cacheClear');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user