Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/DomainsController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API\V4; | namespace App\Http\Controllers\API\V4; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Http\Controllers\Controller; | use App\Http\Controllers\Controller; | ||||
use App\Backends\LDAP; | use App\Backends\LDAP; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Auth; | |||||
class DomainsController extends Controller | class DomainsController extends Controller | ||||
{ | { | ||||
/** | /** | ||||
* Return a list of domains owned by the current user | * Return a list of domains owned by the current user | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function index() | public function index() | ||||
{ | { | ||||
$user = Auth::guard()->user(); | $user = $this->guard()->user(); | ||||
$list = []; | $list = []; | ||||
foreach ($user->domains() as $domain) { | foreach ($user->domains() as $domain) { | ||||
if (!$domain->isPublic()) { | if (!$domain->isPublic()) { | ||||
$data = $domain->toArray(); | $data = $domain->toArray(); | ||||
$data = array_merge($data, self::domainStatuses($domain)); | $data = array_merge($data, self::domainStatuses($domain)); | ||||
$list[] = $data; | $list[] = $data; | ||||
} | } | ||||
Show All 16 Lines | class DomainsController extends Controller | ||||
* 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\JsonResponse|void | * @return \Illuminate\Http\JsonResponse|void | ||||
*/ | */ | ||||
public function confirm($id) | public function confirm($id) | ||||
{ | { | ||||
$domain = Domain::findOrFail($id); | $domain = Domain::find($id); | ||||
// Only owner (or admin) has access to the domain | if (!$this->checkTenant($domain)) { | ||||
if (!Auth::guard()->user()->canRead($domain)) { | return $this->errorResponse(404); | ||||
} | |||||
if (!$this->guard()->user()->canRead($domain)) { | |||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
if (!$domain->confirm()) { | if (!$domain->confirm()) { | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'error', | 'status' => 'error', | ||||
'message' => \trans('app.domain-verify-error'), | 'message' => \trans('app.domain-verify-error'), | ||||
]); | ]); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | class DomainsController extends Controller | ||||
* 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\JsonResponse|void | * @return \Illuminate\Http\JsonResponse|void | ||||
*/ | */ | ||||
public function show($id) | public function show($id) | ||||
{ | { | ||||
$domain = Domain::withEnvTenant()->findOrFail($id); | $domain = Domain::find($id); | ||||
// Only owner (or admin) has access to the domain | if (!$this->checkTenant($domain)) { | ||||
if (!Auth::guard()->user()->canRead($domain)) { | return $this->errorResponse(404); | ||||
} | |||||
if (!$this->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 All 15 Lines | class DomainsController extends Controller | ||||
* Fetch domain status (and reload setup process) | * Fetch domain status (and reload setup process) | ||||
* | * | ||||
* @param int $id Domain identifier | * @param int $id Domain identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function status($id) | public function status($id) | ||||
{ | { | ||||
$domain = Domain::withEnvTenant()->findOrFail($id); | $domain = Domain::find($id); | ||||
if (!$this->checkTenant($domain)) { | |||||
return $this->errorResponse(404); | |||||
} | |||||
// Only owner (or admin) has access to the domain | if (!$this->guard()->user()->canRead($domain)) { | ||||
if (!Auth::guard()->user()->canRead($domain)) { | |||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$response = self::statusInfo($domain); | $response = self::statusInfo($domain); | ||||
if (!empty(request()->input('refresh'))) { | if (!empty(request()->input('refresh'))) { | ||||
$updated = false; | $updated = false; | ||||
$last_step = 'none'; | $last_step = 'none'; | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |