Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/DomainsController.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | class DomainsController extends Controller | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse|void | * @return \Illuminate\Http\JsonResponse|void | ||||
*/ | */ | ||||
public function confirm($id) | public function confirm($id) | ||||
{ | { | ||||
$domain = Domain::findOrFail($id); | $domain = Domain::findOrFail($id); | ||||
// Only owner (or admin) has access to the domain | // Only owner (or admin) has access to the domain | ||||
if (!self::hasAccess($domain)) { | if (!Auth::guard()->user()->canRead($domain)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
if (!$domain->confirm()) { | if (!$domain->confirm()) { | ||||
return response()->json(['status' => 'error']); | return response()->json(['status' => 'error']); | ||||
} | } | ||||
return response()->json([ | return response()->json([ | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | class DomainsController extends Controller | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse|void | * @return \Illuminate\Http\JsonResponse|void | ||||
*/ | */ | ||||
public function show($id) | public function show($id) | ||||
{ | { | ||||
$domain = Domain::findOrFail($id); | $domain = Domain::findOrFail($id); | ||||
// Only owner (or admin) has access to the domain | // Only owner (or admin) has access to the domain | ||||
if (!self::hasAccess($domain)) { | if (!Auth::guard()->user()->canRead($domain)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$response = $domain->toArray(); | $response = $domain->toArray(); | ||||
// Add hash information to the response | // Add hash information to the response | ||||
$response['hash_text'] = $domain->hash(Domain::HASH_TEXT); | $response['hash_text'] = $domain->hash(Domain::HASH_TEXT); | ||||
$response['hash_cname'] = $domain->hash(Domain::HASH_CNAME); | $response['hash_cname'] = $domain->hash(Domain::HASH_CNAME); | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | protected static function getDNSConfig(Domain $domain): array | ||||
";", | ";", | ||||
"@ IN A <some-ip>", | "@ IN A <some-ip>", | ||||
"www IN A <some-ip>", | "www IN A <some-ip>", | ||||
";", | ";", | ||||
"{$hash_cname}.{$domain->namespace}. IN CNAME {$hash}.{$domain->namespace}.", | "{$hash_cname}.{$domain->namespace}. IN CNAME {$hash}.{$domain->namespace}.", | ||||
"@ 3600 TXT \"{$hash_txt}\"", | "@ 3600 TXT \"{$hash_txt}\"", | ||||
]; | ]; | ||||
} | } | ||||
/** | |||||
* Check if the current user has access to the domain | |||||
* | |||||
* @param \App\Domain $domain The domain | |||||
* | |||||
* @return bool True if current user has access, False otherwise | |||||
*/ | |||||
protected static function hasAccess(Domain $domain): bool | |||||
{ | |||||
$user = Auth::guard()->user(); | |||||
$entitlement = $domain->entitlement()->first(); | |||||
// TODO: Admins | |||||
return $entitlement && $entitlement->owner_id == $user->id; | |||||
} | |||||
} | } |