2021-01-30 20:59:12 +08:00
|
|
|
|
<?php
|
2021-07-26 17:41:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @copyright Copyright (c) 2021 勾股工作室
|
2021-11-24 17:17:29 +08:00
|
|
|
|
* @license https://opensource.org/licenses/Apache-2.0
|
2021-07-26 17:41:59 +08:00
|
|
|
|
* @link https://www.gougucms.com
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-30 20:59:12 +08:00
|
|
|
|
namespace app\admin\validate;
|
2021-07-26 17:41:59 +08:00
|
|
|
|
|
2021-01-30 20:59:12 +08:00
|
|
|
|
use think\Validate;
|
|
|
|
|
|
|
|
|
|
class AdminCheck extends Validate
|
|
|
|
|
{
|
2021-08-31 23:40:54 +08:00
|
|
|
|
protected $regex = [ 'checkUser' => '/^[A-Za-z]{1}[A-Za-z0-9_-]{4,19}$/'];
|
|
|
|
|
|
2021-01-30 20:59:12 +08:00
|
|
|
|
protected $rule = [
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'username' => 'require|regex:checkUser|unique:admin',
|
|
|
|
|
'pwd' => 'require|min:6|confirm',
|
|
|
|
|
'edit_pwd' => 'min:6|confirm',
|
|
|
|
|
'mobile' => 'require|mobile',
|
|
|
|
|
'nickname' => 'require|chsAlpha',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'group_id' => 'require',
|
|
|
|
|
'id' => 'require',
|
|
|
|
|
'status' => 'require|checkStatus:-1,1',
|
|
|
|
|
'old_pwd' => 'require|different:pwd',
|
2021-01-30 20:59:12 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $message = [
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'username.require' => '登录账号不能为空',
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'username.regex' => '登录账号必须是以字母开头,只能包含字母数字下划线和减号,5到20位',
|
|
|
|
|
'username.unique' => '同样的登录账号已经存在',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'pwd.require' => '密码不能为空',
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'pwd.min' => '密码至少要6个字符',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'pwd.confirm' => '两次密码不一致',
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'edit_pwd.min' => '密码至少要6个字符',
|
|
|
|
|
'edit_pwd.confirm' => '两次密码不一致',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'mobile.require' => '手机不能为空',
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'mobile.mobile' => '手机格式错误',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'nickname.require' => '昵称不能为空',
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'nickname.chsAlpha' => '昵称只能是汉子和字母',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'group_id.require' => '至少要选择一个用户角色',
|
|
|
|
|
'id.require' => '缺少更新条件',
|
|
|
|
|
'status.require' => '状态为必选',
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'status.checkStatus' => '系统所有者不能被禁用',
|
2021-07-26 17:41:59 +08:00
|
|
|
|
'old_pwd.require' => '请提供旧密码',
|
|
|
|
|
'old_pwd.different' => '新密码不能和旧密码一样',
|
2021-01-30 20:59:12 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $scene = [
|
2021-08-31 23:40:54 +08:00
|
|
|
|
'add' => ['mobile', 'nickname', 'group_id', 'pwd', 'username', 'status'],
|
|
|
|
|
'edit' => ['mobile', 'nickname', 'group_id', 'edit_pwd','id', 'username', 'status'],
|
|
|
|
|
'editPersonal' => ['mobile', 'nickname'],
|
2021-01-30 20:59:12 +08:00
|
|
|
|
'editpwd' => ['old_pwd', 'pwd'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 自定义验证规则
|
2021-07-26 17:41:59 +08:00
|
|
|
|
protected function checkStatus($value, $rule, $data)
|
2021-01-30 20:59:12 +08:00
|
|
|
|
{
|
2021-07-26 17:41:59 +08:00
|
|
|
|
if ($value == -1 and $data['id'] == 1) {
|
2021-01-30 20:59:12 +08:00
|
|
|
|
return $rule == false;
|
|
|
|
|
}
|
|
|
|
|
return $rule == true;
|
|
|
|
|
}
|
2021-07-26 17:41:59 +08:00
|
|
|
|
}
|