schneespur/app/Http/Controllers/Admin/CustomerPortalController.php
Michael 2c63440ed8 Revert: move code back to project root from schneespur/ subdirectory
- Reverts the schneespur/ subdirectory restructure (b8e426b)
- Restores package.json and vite.config.js (needed for npm build, were
  removed in an earlier cleanup before the restructure)
- Updates public/build/ assets with current Vite output (new content hashes)
2026-05-17 18:24:26 +00:00

69 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Mail\PortalCredentialsMail;
use App\Models\Customer;
use App\Services\NotificationLogService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
class CustomerPortalController extends Controller
{
public function setupAccess(Request $request, Customer $customer, NotificationLogService $logService): RedirectResponse
{
if (! $customer->email) {
return redirect()
->route('admin.customers.edit', $customer)
->with('error', __('customer.portal_no_email'));
}
$isReset = $customer->getOriginal('password') !== null;
$plainPassword = Str::random(12);
$customer->password = $plainPassword;
$customer->portal_enabled = true;
$customer->save();
try {
Mail::to($customer->email)->send(new PortalCredentialsMail($customer, $plainPassword, $isReset));
$logService->logSentForCustomer($customer, 'portal_credentials', $customer->email, [
'action' => $isReset ? 'reset' : 'setup',
]);
$flashKey = $isReset ? 'customer.portal_flash_reset' : 'customer.portal_flash_setup';
return redirect()
->route('admin.customers.edit', $customer)
->with('success', __($flashKey, ['name' => $customer->name]));
} catch (\Throwable $e) {
$logService->logFailedForCustomer($customer, 'portal_credentials', $customer->email, $e->getMessage(), [
'action' => $isReset ? 'reset' : 'setup',
]);
return redirect()
->route('admin.customers.edit', $customer)
->with('error', __('customer.portal_flash_email_failed', ['name' => $customer->name]));
}
}
public function updateSettings(Request $request, Customer $customer): RedirectResponse
{
$validated = $request->validate([
'portal_enabled' => ['required', 'boolean'],
'portal_show_gps' => ['required', 'boolean'],
'portal_show_photos' => ['required', 'boolean'],
'portal_show_driver_name' => ['required', 'boolean'],
]);
$customer->update($validated);
return redirect()
->route('admin.customers.edit', $customer)
->with('success', __('customer.portal_flash_settings_updated', ['name' => $customer->name]));
}
}