mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-25 11:58:19 +02:00
Added domain check page
This commit is contained in:
parent
512de0552a
commit
6855dbaccd
9 changed files with 248 additions and 22 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Domain;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
@ -11,9 +11,48 @@ class DomainsController extends Controller
|
|||
{
|
||||
public function view(Request $request, Response $response)
|
||||
{
|
||||
$userModel = new User($this->container->get('db'));
|
||||
$users = $userModel->getAllUsers();
|
||||
return view($response,'admin/domains/index.twig', compact('users'));
|
||||
return view($response,'admin/domains/view.twig');
|
||||
}
|
||||
|
||||
public function check(Request $request, Response $response)
|
||||
{
|
||||
if ($request->getMethod() === 'POST') {
|
||||
// Retrieve POST data
|
||||
$data = $request->getParsedBody();
|
||||
$domainName = $data['domain_name'] ?? null;
|
||||
|
||||
if ($domainName) {
|
||||
$domainModel = new Domain($this->container->get('db'));
|
||||
$availability = $domainModel->getDomainByName($domainName);
|
||||
|
||||
// Convert the DB result into a boolean '0' or '1'
|
||||
$availability = $availability ? '0' : '1';
|
||||
|
||||
$invalid_label = validate_label($domainName, $this->container->get('db'));
|
||||
|
||||
// Check if the domain is Invalid
|
||||
if ($invalid_label) {
|
||||
$status = $invalid_label;
|
||||
$isAvailable = 0;
|
||||
} else {
|
||||
$isAvailable = $availability;
|
||||
$status = null;
|
||||
|
||||
// Check if the domain is unavailable
|
||||
if ($availability === '0') {
|
||||
$status = 'In use';
|
||||
}
|
||||
}
|
||||
|
||||
return view($response, 'admin/domains/check.twig', [
|
||||
'isAvailable' => $isAvailable,
|
||||
'domainName' => $domainName,
|
||||
'status' => $status,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Default view for GET requests or if POST data is not set
|
||||
return view($response,'admin/domains/check.twig');
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue