Add customer/user's email validation
This commit is contained in:
parent
beaa84e380
commit
09f83c2044
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Auth;
|
namespace App\Http\Requests\Auth;
|
||||||
|
|
||||||
|
use App\Traits\Contacts;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class User extends FormRequest
|
class User extends FormRequest
|
||||||
{
|
{
|
||||||
|
use Contacts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
@ -29,12 +33,22 @@ class User extends FormRequest
|
|||||||
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$email = ['required', 'email'];
|
||||||
|
|
||||||
if ($this->getMethod() == 'PATCH') {
|
if ($this->getMethod() == 'PATCH') {
|
||||||
// Updating user
|
// Updating user
|
||||||
$id = is_numeric($this->user) ? $this->user : $this->user->getAttribute('id');
|
$id = is_numeric($this->user) ? $this->user : $this->user->getAttribute('id');
|
||||||
$password = '';
|
$password = '';
|
||||||
$companies = $this->user->can('read-common-companies') ? 'required' : '';
|
$companies = $this->user->can('read-common-companies') ? 'required' : '';
|
||||||
$roles = $this->user->can('read-auth-roles') ? 'required' : '';
|
$roles = $this->user->can('read-auth-roles') ? 'required' : '';
|
||||||
|
|
||||||
|
if ($this->user->contact) {
|
||||||
|
$email[] = Rule::unique('contacts')
|
||||||
|
->ignore($this->user->contact->id)
|
||||||
|
->where('company_id', company_id())
|
||||||
|
->where('type', $this->getCustomerTypes())
|
||||||
|
->where('deleted_at');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Creating user
|
// Creating user
|
||||||
$id = null;
|
$id = null;
|
||||||
@ -43,9 +57,11 @@ class User extends FormRequest
|
|||||||
$roles = 'required';
|
$roles = 'required';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$email[] = Rule::unique('users')->ignore($id)->where('deleted_at');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'email' => 'required|email|unique:users,email,' . $id . ',id,deleted_at,NULL',
|
'email' => $email,
|
||||||
'password' => $password . 'confirmed',
|
'password' => $password . 'confirmed',
|
||||||
'companies' => $companies,
|
'companies' => $companies,
|
||||||
'roles' => $roles,
|
'roles' => $roles,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Requests\Common;
|
namespace App\Http\Requests\Common;
|
||||||
|
|
||||||
use App\Abstracts\Http\FormRequest;
|
use App\Abstracts\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class Contact extends FormRequest
|
class Contact extends FormRequest
|
||||||
{
|
{
|
||||||
@ -23,7 +24,7 @@ class Contact extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
$email = '';
|
$email = [];
|
||||||
$required = '';
|
$required = '';
|
||||||
|
|
||||||
$type = $this->request->get('type', 'customer');
|
$type = $this->request->get('type', 'customer');
|
||||||
@ -43,7 +44,18 @@ class Contact extends FormRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->request->get('email'))) {
|
if (!empty($this->request->get('email'))) {
|
||||||
$email = 'email|unique:contacts,NULL,' . $id . ',id,company_id,' . $company_id . ',type,' . $type . ',deleted_at,NULL';
|
$email[] = 'email';
|
||||||
|
$email[] = Rule::unique('contacts')
|
||||||
|
->ignore($id)
|
||||||
|
->where('company_id', $company_id)
|
||||||
|
->where('type', $type)
|
||||||
|
->where('deleted_at');
|
||||||
|
|
||||||
|
if (isset($model) && $this->$model->user_id) {
|
||||||
|
$email[] = Rule::unique('users')
|
||||||
|
->ignore($this->$model->user_id)
|
||||||
|
->where('deleted_at');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Portal;
|
namespace App\Http\Requests\Portal;
|
||||||
|
|
||||||
|
use App\Traits\Contacts;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class Profile extends FormRequest
|
class Profile extends FormRequest
|
||||||
{
|
{
|
||||||
|
use Contacts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
@ -31,9 +35,25 @@ class Profile extends FormRequest
|
|||||||
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$email = [
|
||||||
|
'required',
|
||||||
|
'email',
|
||||||
|
Rule::unique('users')
|
||||||
|
->ignore($id)
|
||||||
|
->where('deleted_at'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (user()->contact) {
|
||||||
|
$email[] = Rule::unique('contacts')
|
||||||
|
->ignore(user()->contact->id)
|
||||||
|
->where('company_id', company_id())
|
||||||
|
->where('type', $this->getCustomerTypes())
|
||||||
|
->where('deleted_at');
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'email' => 'required|email|unique:users,email,' . $id . ',id,deleted_at,NULL',
|
'email' => $email,
|
||||||
'password' => 'confirmed',
|
'password' => 'confirmed',
|
||||||
'picture' => $picture,
|
'picture' => $picture,
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user