VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.7 KiB
PHP
86 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Email;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\EmailDomain\EmailDomainClient;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
/** Email domain setup (add → publish DNS → verify), via the §4-D API. */
|
|
class DomainsController extends Controller
|
|
{
|
|
public function __construct(private EmailDomainClient $domains) {}
|
|
|
|
private function pid(): string
|
|
{
|
|
return (string) ladill_account()->public_id;
|
|
}
|
|
|
|
public function index(): View
|
|
{
|
|
$domains = [];
|
|
$error = null;
|
|
try {
|
|
$domains = $this->domains->forUser($this->pid());
|
|
} catch (\Throwable $e) {
|
|
report($e);
|
|
$error = 'Could not load your domains.';
|
|
}
|
|
|
|
return view('email.domains.index', compact('domains', 'error'));
|
|
}
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$data = $request->validate(['domain' => ['required', 'string', 'max:253']]);
|
|
|
|
try {
|
|
$domain = $this->domains->create($this->pid(), strtolower(trim($data['domain'])));
|
|
|
|
return redirect()->route('email.domains.show', $domain['id'])
|
|
->with('success', 'Domain added — publish the DNS records below, then verify.');
|
|
} catch (\Throwable $e) {
|
|
report($e);
|
|
|
|
return back()->with('error', 'Could not add that domain. It may already exist.');
|
|
}
|
|
}
|
|
|
|
public function show(int $id): View|RedirectResponse
|
|
{
|
|
try {
|
|
$domain = $this->domains->show($this->pid(), $id);
|
|
} catch (\Throwable $e) {
|
|
return redirect()->route('email.domains.index')->with('error', 'Domain not found.');
|
|
}
|
|
|
|
return view('email.domains.show', ['domain' => $domain]);
|
|
}
|
|
|
|
public function verify(int $id): RedirectResponse
|
|
{
|
|
try {
|
|
$domain = $this->domains->verify($this->pid(), $id);
|
|
$ok = $domain['active'] ?? false;
|
|
|
|
return redirect()->route('email.domains.show', $id)
|
|
->with($ok ? 'success' : 'error', $ok ? 'Domain verified — you can now create mailboxes.' : 'Not verified yet. DNS can take time to propagate.');
|
|
} catch (\Throwable $e) {
|
|
return back()->with('error', 'Verification failed. Try again shortly.');
|
|
}
|
|
}
|
|
|
|
public function destroy(int $id): RedirectResponse
|
|
{
|
|
try {
|
|
$this->domains->delete($this->pid(), $id);
|
|
} catch (\Throwable $e) {
|
|
return back()->with('error', 'Could not remove that domain.');
|
|
}
|
|
|
|
return redirect()->route('email.domains.index')->with('success', 'Domain removed.');
|
|
}
|
|
}
|