修改auth认证

This commit is contained in:
wuyanwen
2020-01-07 17:27:55 +08:00
parent f7ac1a23bf
commit c9b39327a5
8 changed files with 280 additions and 66 deletions

View File

@@ -8,6 +8,14 @@ use think\Validate;
class CatchRequest extends Request
{
/**
* 批量验证
*
* @var bool
*/
protected $batch = false;
/**
* Request constructor.
* @throws \Exception
@@ -30,7 +38,45 @@ class CatchRequest extends Request
{
try {
$validate = new Validate();
// 批量验证
if ($this->batch) {
$validate->batch($this->batch);
}
// 自定义规则
if (method_exists($this, 'newRules')) {
foreach ($this->newRules() as $rule) {
$validate->extend($rule->type(), [$rule, 'verify'], $rule->message());
}
}
/**
// 场景设置验证
if (property_exists($this, 'scene') && !empty($this->scene)) {
foreach ($this->scene as $scene => $rules) {
$validate->scene($scene);
// 只限制字段
if (!isset($rules['only'])) {
$validate->only($rules);
} else {
$validate->only($rules['only']);
// 新增规则
if (isset($rules['append'])) {
foreach ($rules['append'] as $field => $rule) {
$validate->append($field, $rule);
}
}
// 移除规则
if (isset($rules['remove'])) {
foreach ($rules['remove'] as $field => $rule) {
$validate->remove($field, $rule);
}
}
}
}
}**/
// 验证
if (!$validate->check(request()->param(), $this->rules())) {
throw new FailedException($validate->getError());
}