2020-05-28 17:39:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\ClientPortal;
|
|
|
|
|
2021-06-28 11:56:04 +02:00
|
|
|
use App\Libraries\MultiDB;
|
2021-03-30 14:07:31 +02:00
|
|
|
use App\Models\Account;
|
2020-06-22 10:26:48 +02:00
|
|
|
use App\Models\Company;
|
2021-03-30 14:07:31 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-05-28 17:39:38 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
class RegisterRequest extends FormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2021-06-28 12:31:23 +02:00
|
|
|
$rules = [
|
2020-05-28 17:52:44 +02:00
|
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
|
|
'last_name' => ['required', 'string', 'max:255'],
|
2020-06-18 17:09:28 +02:00
|
|
|
'phone' => ['required', 'string', 'max:255'],
|
2021-06-21 12:53:34 +02:00
|
|
|
'email' => ['required', 'string', 'email:rfc,dns', 'max:255'],
|
2020-05-28 17:39:38 +02:00
|
|
|
'password' => ['required', 'string', 'min:6', 'confirmed'],
|
|
|
|
];
|
2021-06-28 12:31:23 +02:00
|
|
|
|
|
|
|
if ($this->company()->settings->client_portal_terms || $this->company()->settings->client_portal_privacy_policy) {
|
|
|
|
$rules['terms'] = ['required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rules;
|
2020-05-28 17:39:38 +02:00
|
|
|
}
|
2020-06-22 10:26:48 +02:00
|
|
|
|
|
|
|
public function company()
|
2021-06-28 12:31:23 +02:00
|
|
|
{
|
2021-06-28 11:56:04 +02:00
|
|
|
|
|
|
|
//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();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-06-22 10:26:48 +02:00
|
|
|
if ($this->company_key) {
|
|
|
|
return Company::where('company_key', $this->company_key)->firstOrFail();
|
|
|
|
}
|
|
|
|
|
2021-03-30 14:07:31 +02:00
|
|
|
if (!$this->route()->parameter('company_key') && Ninja::isSelfHost()) {
|
|
|
|
$company = Account::first()->default_company;
|
|
|
|
|
2021-06-28 11:56:04 +02:00
|
|
|
if(!$company->client_can_register)
|
|
|
|
abort(403, "This page is restricted");
|
2021-03-30 14:07:31 +02:00
|
|
|
|
|
|
|
return $company;
|
|
|
|
}
|
|
|
|
|
2021-06-28 11:56:04 +02:00
|
|
|
if (Ninja::isHosted()) {
|
|
|
|
|
|
|
|
$subdomain = explode('.', $this->getHost())[0];
|
2021-06-28 12:31:23 +02:00
|
|
|
|
2021-06-28 11:56:04 +02:00
|
|
|
$query = [
|
|
|
|
'subdomain' => $subdomain,
|
|
|
|
'portal_mode' => 'subdomain',
|
|
|
|
];
|
|
|
|
|
|
|
|
if($company = MultiDB::findAndSetDbByDomain($query))
|
|
|
|
return $company;
|
2021-06-28 12:31:23 +02:00
|
|
|
|
2021-06-28 11:56:04 +02:00
|
|
|
$query = [
|
|
|
|
'portal_domain' => $this->getSchemeAndHttpHost(),
|
|
|
|
'portal_mode' => 'domain',
|
|
|
|
];
|
|
|
|
|
|
|
|
if($company = MultiDB::findAndSetDbByDomain($query))
|
|
|
|
return $company;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(400, 'Register request not found.');
|
2020-06-22 10:26:48 +02:00
|
|
|
}
|
2020-05-28 17:39:38 +02:00
|
|
|
}
|