first commit
This commit is contained in:
69
app/Core/Validator/User/ChangePasswordValidator.php
Normal file
69
app/Core/Validator/User/ChangePasswordValidator.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Validator\User;
|
||||
|
||||
use App\Core\Repository\User\UserRepository;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
use App\Core\Validator\BaseValidator;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ChangePasswordValidator extends BaseValidator
|
||||
{
|
||||
private $userRepository;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
UserRepository $userRepository,
|
||||
Translator $translator,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct($translator, $container);
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function rules($params = null)
|
||||
{
|
||||
return
|
||||
[
|
||||
"user_id" => "required",
|
||||
"checkOldPassword" => "accepted",
|
||||
'password' => 'required|max:20|min:6|confirmed',
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$thisMessages = [];
|
||||
return array_merge(parent::messages() , $thisMessages);
|
||||
}
|
||||
|
||||
public function checkOldPassword($params)
|
||||
{
|
||||
try {
|
||||
|
||||
|
||||
$user = User::where('id', $params['user_id'])->first();
|
||||
$result = Hash::check($params['old_password'], $user->password) ;
|
||||
return $result ? true : false;
|
||||
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
|
||||
{
|
||||
$params["checkOldPassword"] = $this->checkOldPassword(['user_id' => $params["user_id"], 'old_password' => $params["old_password"] ]);
|
||||
return $this->make($params, $this->rules($params), $this->messages());
|
||||
}
|
||||
|
||||
}
|
||||
55
app/Core/Validator/User/ResetPasswordValidator.php
Normal file
55
app/Core/Validator/User/ResetPasswordValidator.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Validator\User;
|
||||
|
||||
use App\Core\Repository\User\UserRepository;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
use App\Core\Validator\BaseValidator;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ResetPasswordValidator extends BaseValidator
|
||||
{
|
||||
private $userRepository;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
UserRepository $userRepository,
|
||||
Translator $translator,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct($translator, $container);
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function rules($params = null)
|
||||
{
|
||||
return
|
||||
[
|
||||
'email' => 'required|email',
|
||||
'hash_key' => 'required|min:128',
|
||||
'password' => 'required|max:20|min:6|confirmed',
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$thisMessages = [];
|
||||
return array_merge(parent::messages() , $thisMessages);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
|
||||
{
|
||||
return $this->make($params, $this->rules($params), $this->messages());
|
||||
}
|
||||
|
||||
}
|
||||
73
app/Core/Validator/User/UserCreateValidator.php
Normal file
73
app/Core/Validator/User/UserCreateValidator.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Validator\User;
|
||||
|
||||
use App\Core\Repository\User\UserRepository;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
|
||||
use App\Core\Validator\BaseValidator;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UserCreateValidator extends BaseValidator
|
||||
{
|
||||
private $userRepository;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
UserRepository $userRepository,
|
||||
Translator $translator,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct($translator, $container);
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function rules($params = null)
|
||||
{
|
||||
return
|
||||
[
|
||||
'name' => 'required|min:3|max:150',
|
||||
'email' => 'required|email',
|
||||
'isUniqueEmail' => 'accepted',
|
||||
'password' => 'required|max:20'
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$thisMessages = [];
|
||||
return array_merge(parent::messages() , $thisMessages);
|
||||
}
|
||||
|
||||
public function isUniqueEmail($email)
|
||||
{
|
||||
try {
|
||||
$criteria =
|
||||
[
|
||||
"criteria" =>
|
||||
[
|
||||
["field" => "email", "condition" => "=", "value" => $email]
|
||||
]
|
||||
];
|
||||
$result = $this->userRepository->findByCriteria($criteria);
|
||||
|
||||
return $result ? false : true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
|
||||
{
|
||||
$params["isUniqueEmail"] = $this->isUniqueEmail($params["email"]);
|
||||
return $this->make($params, $this->rules($params), $this->messages());
|
||||
}
|
||||
|
||||
}
|
||||
50
app/Core/Validator/User/UserLoginValidator.php
Normal file
50
app/Core/Validator/User/UserLoginValidator.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Validator\User;
|
||||
|
||||
use App\Core\Repository\User\UserRepository;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
|
||||
use App\Core\Validator\BaseValidator;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UserLoginValidator extends BaseValidator
|
||||
{
|
||||
private $userRepository;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
UserRepository $userRepository,
|
||||
Translator $translator,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct($translator, $container);
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function rules($params = null)
|
||||
{
|
||||
return
|
||||
[
|
||||
'email' => 'required|email',
|
||||
'password' => 'required'
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$thisMessages = [];
|
||||
return array_merge(parent::messages() , $thisMessages);
|
||||
}
|
||||
|
||||
public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
|
||||
{
|
||||
return $this->make($params, $this->rules($params), $this->messages());
|
||||
}
|
||||
|
||||
}
|
||||
52
app/Core/Validator/User/UserNewPasswordValidator.php
Normal file
52
app/Core/Validator/User/UserNewPasswordValidator.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Validator\User;
|
||||
|
||||
use App\Core\Repository\User\UserRepository;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
|
||||
use App\Core\Validator\BaseValidator;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UserNewPasswordValidator extends BaseValidator
|
||||
{
|
||||
private $userRepository;
|
||||
|
||||
public function __construct
|
||||
(
|
||||
UserRepository $userRepository,
|
||||
Translator $translator,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct($translator, $container);
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function rules($params = null)
|
||||
{
|
||||
return
|
||||
[
|
||||
'email' => 'required|email',
|
||||
'hash_key' => 'required|min:128',
|
||||
'password' => 'required|max:20|min:6|confirmed',
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$thisMessages = [];
|
||||
return array_merge(parent::messages() , $thisMessages);
|
||||
}
|
||||
|
||||
|
||||
public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
|
||||
{
|
||||
return $this->make($params, $this->rules($params), $this->messages());
|
||||
}
|
||||
|
||||
}
|
||||
44
app/Core/Validator/User/UserProfileUpdateValidator.php
Normal file
44
app/Core/Validator/User/UserProfileUpdateValidator.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Validator\User;
|
||||
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
|
||||
use App\Core\Validator\BaseValidator;
|
||||
|
||||
class UserProfileUpdateValidator extends BaseValidator
|
||||
{
|
||||
public function __construct
|
||||
(
|
||||
Translator $translator,
|
||||
Container $container
|
||||
)
|
||||
{
|
||||
parent::__construct($translator, $container);
|
||||
}
|
||||
|
||||
public function rules($params = null)
|
||||
{
|
||||
return
|
||||
[
|
||||
"name" => 'required',
|
||||
"surname" => 'required',
|
||||
"gender" => 'nullable',
|
||||
"language" => 'required',
|
||||
"phone" => 'nullable'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
$thisMessages = [];
|
||||
return array_merge(parent::messages() , $thisMessages);
|
||||
}
|
||||
|
||||
public function validate(array $params, array $rules = [], array $messages = [], array $customAttributes = [])
|
||||
{
|
||||
return $this->make($params, $this->rules($params), $this->messages());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user