diff --git a/app/Http/Middleware/ContactRegister.php b/app/Http/Middleware/ContactRegister.php index 116dfe22d472..ade62aa84974 100644 --- a/app/Http/Middleware/ContactRegister.php +++ b/app/Http/Middleware/ContactRegister.php @@ -33,7 +33,8 @@ class ContactRegister if($company) { - abort_unless($company->client_can_register, 404); + if(! $company->client_can_register) + abort(400, 'Registration disabled'); $request->merge(['key' => $company->company_key]); @@ -49,7 +50,9 @@ class ContactRegister if($company = Company::where($query)->first()) { - abort_unless($company->client_can_register, 404); + + if(! $company->client_can_register) + abort(400, 'Registration disabled'); $request->merge(['key' => $company->company_key]); @@ -62,7 +65,10 @@ class ContactRegister if ($request->route()->parameter('company_key') && Ninja::isSelfHost()) { $company = Company::where('company_key', $request->company_key)->firstOrFail(); - abort_unless($company->client_can_register, 404); + if(! (bool)$company->client_can_register); + abort(400, 'Registration disabled'); + + $request->merge(['key' => $company->company_key]); return $next($request); } @@ -72,7 +78,8 @@ class ContactRegister if (!$request->route()->parameter('company_key') && Ninja::isSelfHost()) { $company = Account::first()->default_company; - abort_unless($company->client_can_register, 404); + if(! $company->client_can_register) + abort(400, 'Registration disabled'); $request->merge(['key' => $company->company_key]); diff --git a/app/Http/Requests/ClientPortal/RegisterRequest.php b/app/Http/Requests/ClientPortal/RegisterRequest.php index 6b74201d79d3..8ec7d723b8d2 100644 --- a/app/Http/Requests/ClientPortal/RegisterRequest.php +++ b/app/Http/Requests/ClientPortal/RegisterRequest.php @@ -2,6 +2,7 @@ namespace App\Http\Requests\ClientPortal; +use App\Libraries\MultiDB; use App\Models\Account; use App\Models\Company; use App\Utils\Ninja; @@ -36,10 +37,11 @@ class RegisterRequest extends FormRequest } public function company() - { - if ($this->subdomain) { - return Company::where('subdomain', $this->subdomain)->firstOrFail(); - } + { + + //this should be all we need, the rest SHOULD be redundant because of our Middleware + if ($this->key) + return Company::where('company_key', $this->key)->first(); if ($this->company_key) { return Company::where('company_key', $this->company_key)->firstOrFail(); @@ -48,11 +50,34 @@ class RegisterRequest extends FormRequest if (!$this->route()->parameter('company_key') && Ninja::isSelfHost()) { $company = Account::first()->default_company; - abort_unless($company->client_can_register, 404); + if(!$company->client_can_register) + abort(403, "This page is restricted"); return $company; } - abort(404, 'Register request not found.'); + if (Ninja::isHosted()) { + + $subdomain = explode('.', $this->getHost())[0]; + + $query = [ + 'subdomain' => $subdomain, + 'portal_mode' => 'subdomain', + ]; + + if($company = MultiDB::findAndSetDbByDomain($query)) + return $company; + + $query = [ + 'portal_domain' => $this->getSchemeAndHttpHost(), + 'portal_mode' => 'domain', + ]; + + if($company = MultiDB::findAndSetDbByDomain($query)) + return $company; + + } + + abort(400, 'Register request not found.'); } }