1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Http/Requests/ClientPortal/RegisterRequest.php

59 lines
1.5 KiB
PHP
Raw Normal View History

2020-05-28 17:39:38 +02:00
<?php
namespace App\Http\Requests\ClientPortal;
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()
{
return [
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'],
2020-10-12 23:27:42 +02:00
'email' => ['required', 'string', 'email:rfc,dns', 'max:255', 'unique:client_contacts'],
2020-05-28 17:39:38 +02:00
'password' => ['required', 'string', 'min:6', 'confirmed'],
];
}
2020-06-22 10:26:48 +02:00
public function company()
{
if ($this->subdomain) {
return Company::where('subdomain', $this->subdomain)->firstOrFail();
}
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;
abort_unless($company->client_can_register, 404);
return $company;
}
2021-05-24 11:39:21 +02:00
abort(404, 'Register request not found.');
2020-06-22 10:26:48 +02:00
}
2020-05-28 17:39:38 +02:00
}