update folder location
This commit is contained in:
41
src/User/Validator/AjaxRequestModelValidator.php
Normal file
41
src/User/Validator/AjaxRequestModelValidator.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Validator;
|
||||
|
||||
use Da\User\Contracts\ValidatorInterface;
|
||||
use yii\base\Model;
|
||||
use Yii;
|
||||
use yii\bootstrap\ActiveForm;
|
||||
use yii\web\Response;
|
||||
|
||||
class AjaxRequestModelValidator implements ValidatorInterface
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __construct(Model $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
$request = Yii::$app->request;
|
||||
|
||||
if ($request->getIsAjax() && !$request->getIsPjax()) {
|
||||
if ($this->model->load($request->post())) {
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
echo json_encode(ActiveForm::validate($this->model));
|
||||
Yii::$app->end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/User/Validator/RbacItemsValidator.php
Normal file
34
src/User/Validator/RbacItemsValidator.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Validator;
|
||||
|
||||
use Da\User\Traits\AuthManagerAwareTrait;
|
||||
use Yii;
|
||||
use yii\validators\Validator;
|
||||
|
||||
class RbacItemsValidator extends Validator
|
||||
{
|
||||
use AuthManagerAwareTrait;
|
||||
|
||||
protected function validateValue($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
return [Yii::t('usuario', 'Invalid value'), []];
|
||||
}
|
||||
|
||||
foreach ($value as $item) {
|
||||
if ($this->getAuthManager()->getItem($item) == null) {
|
||||
return [Yii::t('usuario', 'There is neither role nor permission with name "{0}"', [$item]), []];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/User/Validator/RbacRuleValidator.php
Normal file
36
src/User/Validator/RbacRuleValidator.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Validator;
|
||||
|
||||
use ReflectionClass;
|
||||
use Exception;
|
||||
use yii\validators\Validator;
|
||||
use Yii;
|
||||
|
||||
class RbacRuleValidator extends Validator
|
||||
{
|
||||
protected function validateValue($value)
|
||||
{
|
||||
try {
|
||||
$class = new ReflectionClass($value);
|
||||
} catch (Exception $e) {
|
||||
return [Yii::t('usuario', 'Class "{0}" does not exist', $value), []];
|
||||
}
|
||||
|
||||
if ($class->isInstantiable() == false) {
|
||||
return [Yii::t('usuario', 'Rule class can not be instantiated'), []];
|
||||
}
|
||||
if ($class->isSubclassOf('\yii\rbac\Rule') == false) {
|
||||
return [Yii::t('usuario', 'Rule class must extend "yii\\rbac\\Rule"'), []];
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/User/Validator/TimeZoneValidator.php
Normal file
29
src/User/Validator/TimeZoneValidator.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Validator;
|
||||
|
||||
use Da\User\Contracts\ValidatorInterface;
|
||||
|
||||
class TimeZoneValidator implements ValidatorInterface
|
||||
{
|
||||
protected $timezone;
|
||||
|
||||
public function __construct($timezone)
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
return in_array($this->timezone, timezone_identifiers_list());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user