Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/DomainsController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API; | namespace App\Http\Controllers\API; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Http\Controllers\Controller; | use App\Http\Controllers\Controller; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
class DomainsController extends Controller | class DomainsController extends Controller | ||||
{ | { | ||||
/** | /** | ||||
* Display a listing of the resource. | * Display a listing of the resource. | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
// | // | ||||
} | } | ||||
/** | /** | ||||
* Show the form for creating a new resource. | * Show the form for creating a new resource. | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function create() | public function create() | ||||
{ | { | ||||
// | // | ||||
} | } | ||||
/** | /** | ||||
* Confirm ownership of the specified domain (via DNS check). | * Confirm ownership of the specified domain (via DNS check). | ||||
* | * | ||||
* @param int $id Domain identifier | * @param int $id Domain identifier | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @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 (!self::hasAccess($domain)) { | ||||
return abort(403); | return abort(403); | ||||
} | } | ||||
if (!$domain->confirm()) { | if (!$domain->confirm()) { | ||||
return response()->json(['status' => 'error']); | return response()->json(['status' => 'error']); | ||||
} | } | ||||
return response()->json(['status' => 'success']); | return response()->json(['status' => 'success']); | ||||
} | } | ||||
/** | /** | ||||
* Remove the specified resource from storage. | * Remove the specified resource from storage. | ||||
* | * | ||||
* @param int $id | * @param int $id | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function destroy($id) | public function destroy($id) | ||||
{ | { | ||||
// | // | ||||
} | } | ||||
/** | /** | ||||
* Show the form for editing the specified resource. | * Show the form for editing the specified resource. | ||||
Show All 19 Lines | public function store(Request $request) | ||||
// | // | ||||
} | } | ||||
/** | /** | ||||
* Get the information about the specified domain. | * Get the information about the specified domain. | ||||
* | * | ||||
* @param int $id Domain identifier | * @param int $id Domain identifier | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @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 (!self::hasAccess($domain)) { | ||||
return abort(403); | return abort(403); | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | protected static function getDNSConfig(Domain $domain): array | ||||
"{$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 | * Check if the current user has access to the domain | ||||
* | * | ||||
* @param \App\Domain Domain | * @param \App\Domain $domain The domain | ||||
* | * | ||||
* @return bool True if current user has access, False otherwise | * @return bool True if current user has access, False otherwise | ||||
*/ | */ | ||||
protected static function hasAccess(Domain $domain): bool | protected static function hasAccess(Domain $domain): bool | ||||
{ | { | ||||
$user = Auth::guard()->user(); | $user = Auth::guard()->user(); | ||||
$entitlement = $domain->entitlement()->first(); | $entitlement = $domain->entitlement()->first(); | ||||
// TODO: Admins | // TODO: Admins | ||||
return $entitlement && $entitlement->owner_id == $user->id; | return $entitlement && $entitlement->owner_id == $user->id; | ||||
} | } | ||||
} | } |