SettingSiteValidate.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\validate;
use app\admin\model\RouteModel;
use think\Validate;
class SettingSiteValidate extends Validate
{
protected $rule = [
'options.site_name' => 'require',
'admin_settings.admin_password' => 'alphaNum|checkAlias'
];
protected $message = [
'options.site_name.require' => '网站名称不能为空',
'admin_settings.admin_password.alphaNum' => '后台加密码只能是英文字母和数字',
'admin_settings.admin_password.checkAlias' => '此加密码不能使用!',
];
// 自定义验证规则
protected function checkAlias($value, $rule, $data)
{
if (empty($value)) {
return true;
}
if(preg_match('/^\d+$/',$value)){
return "加密码不能是纯数字!";
}
$routeModel = new RouteModel();
$fullUrl = $routeModel->buildFullUrl('admin/Index/index', []);
if (!$routeModel->existsRoute($value.'$', $fullUrl)) {
return true;
} else {
return "URL规则已经存在,无法设置此加密码!";
}
}
}